VS code play button is goofy
When I build and run using the terminal the program runs just fine but if I use the play button or "run project assiosiated with this file" my relative path doesnt work and I get an error
27 Replies
Do you have a
launch.json
? https://code.visualstudio.com/Docs/editor/debugging
Assuming you're using the C# extension it should offer to make one for youDebugging in Visual Studio Code
One of the great things in Visual Studio Code is debugging support. Set breakpoints, step-in, inspect variables and more.
That's not really a vsc issue, this is how all ides work. What do you expect it to do? Use the directory of the current file as the working directory? That of the Program.cs file? Of the project file? It's ambiguous, so using the output directory is the only thing that makes sense.
If you need to access a file, don't rely on relative paths, or copy it to the output directory, or embed it, etc.
im using relative paths so It can run on a laptop that isnt mine for example my instructors machince
yes I do
it used to work two weeks ago I didnt change any code between now and then
That's not possible
the working directory is normal when using the terminal but it goes through debug with the play button it goes through bin and stuff
seeing as that I didnt open vs code between then and when it stopped working it very much is possible
Come on guy it's obviously not possible that it just changes its behavior, what are you trying to say...
I've explained it and given you possible ways to solve it, is there still a problem?
yeah and I told you why that wouldnt work
Why does copying the file to the output directory or embedding not work?
you mean putting th efile into bin and debug and all that
shouldnt it do that automatically
Yes, if you set the project properties that say so
how do I do that
Otherwise the file just exists on your disk, how should your project know what to do with it?
I havent been able to find a single properties tab anywhere
its in the project folder
So?
how do I do this
where should I put this? runtimeconfig.json?
Your project file
isnt that a folder
The .csproj file
okay is there a way to do the same thing with a fodler of images
MSBuild supports globbing patterns
yeah i have no idea what that means
alight well chat gpt gave me this: <ItemGroup>
<Content Include="CarPhotos***">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> and everything works now
i have no idea what changed it mustve been an extension updating or something
thank you for the help @ero sorry for being a jerk
There was no extension change, this is how it has worked in all .NET IDEs for years, but I'm glad it works now I guess
well I definitely didn’t have that stuff in the project file before so something must’ve changed
Nope
Not on the vscode side anyway
On the user side, most likely
like a setting?
the code didn’t change at all
and I didn’t change any settings