C
C#2w ago
ILuvCatsFr

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