C
C#2mo ago
x

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
lycian
lycian2mo ago
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 you
Debugging in Visual Studio Code
One of the great things in Visual Studio Code is debugging support. Set breakpoints, step-in, inspect variables and more.
ero
ero2mo ago
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.
x
xOP2mo ago
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
ero
ero2mo ago
That's not possible
x
xOP2mo ago
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
ero
ero2mo ago
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?
x
xOP2mo ago
yeah and I told you why that wouldnt work
ero
ero2mo ago
Why does copying the file to the output directory or embedding not work?
x
xOP2mo ago
you mean putting th efile into bin and debug and all that shouldnt it do that automatically
ero
ero2mo ago
Yes, if you set the project properties that say so
x
xOP2mo ago
how do I do that
ero
ero2mo ago
Otherwise the file just exists on your disk, how should your project know what to do with it?
x
xOP2mo ago
I havent been able to find a single properties tab anywhere its in the project folder
ero
ero2mo ago
So?
x
xOP2mo ago
how do I do this
ero
ero2mo ago
<ItemGroup>
<None Include="File.txt" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<None Include="File.txt" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
x
xOP2mo ago
where should I put this? runtimeconfig.json?
ero
ero2mo ago
Your project file
x
xOP2mo ago
isnt that a folder
ero
ero2mo ago
The .csproj file
x
xOP2mo ago
okay is there a way to do the same thing with a fodler of images
ero
ero2mo ago
MSBuild supports globbing patterns
x
xOP2mo ago
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
ero
ero2mo ago
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
x
xOP2mo ago
well I definitely didn’t have that stuff in the project file before so something must’ve changed
ero
ero2mo ago
Nope Not on the vscode side anyway On the user side, most likely
x
xOP2mo ago
like a setting? the code didn’t change at all and I didn’t change any settings

Did you find this page helpful?