Where to place resource files?
c#, visual-studio-2010
Solution
You can place it anywhere you like in your project (except inside the bin/obj folders). In order to have it copied to your output, you simply need to mark it as "Copy to Output Directory":
- Include the file in the project
- Click the file in Solution Explorer
- Hit `F4`
- In the properties window, change the setting "Copy to Output Directory" to any of "Copy always" or "Copy if newer"
This will list the file in your project msbuild file (.csproj file) like this:
<None Include="data.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
As opposed to:
<None Include="data.csv" />
If you did not change the setting as written above.
As I side note, you may want to avoid the term "resource" since that is normally used for files that are embedded into the assembly (such as .resx files). You could, conceivably, do that with your data.csv file as well: Instead of copying it to the output directory, it would be embedded in your assembly. You would need to access the file in a different way though. To achieve simply change "Build Action" to "Embedded Resource" instead of setting the "Copy to Output Directory" setting.
Problem
If the project has these directories ``` MyProject - bin - Debug - program.exe - Release - program.exe - program.cs ``` Where to place a `data.csv` file that will be parsed by the program? I'd like to have it in the same folder as the program. Do I have to copy it to the Debug and Release dirs? Or is there a better way? Edit I also needed to copy whole directories to output directory, but Visual Studio doesn't have this option. I found the answer here. If the Directory is huge (like in my case) it can be solved to copy only newer files using `/D` xcopy attribute. In my case, I added this command to post-build events (Project->Properties) and it works great: ``` xcopy "$(ProjectDir)\FolderToCopy" "$(TargetDir)\FolderToCopy" /D /E /I /Q /Y ``` (xcopy syntax)