I have a VS 2022 project that has an EXE. When the EXE runs, it wants to open files in the ./data/ and ./saves/ folders.
The problem is that when VS builds the project, it puts the output in myProject\bin\Debug\net8.0
; consequently, my EXE can't find ./data/ and ./saves/.
Setting the 'Base Output Path' doesn't help, because it will still append .\Debug\net8.0
to whatever I put in there.
Using a 'Post-build event' doesn't help, because even though my EXE gets copied to the right place, pressing Run from VS, runs the copy in the Debug\net8.0
directory.
The ugly workaround is to put copies of ./data/ and ./saves/ in each of .\Debug\net8.0
and .\Release\net8.0
Has anyone solved this conundrum?
I know 2 approaches:
Force specify the output path:
<PropertyGroup>
<OutputPath>your\output\path\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
Copy resources to the output path:
<ItemGroup>
<None Update="data\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="saves\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>