I have an Assembly which contains a file with BuildAction = Content and Copy to output = Always. Now I build Executable which depends on Assembly and I expect VisualStudio/MsBuild somehow copy content files to output so Assembly can work. But it doesn’t happen.
Currently I resolve this problem manually: either by adding these files as links to Executable project or copying at build events. Is there any way to resolve this problem in automatic way?
If you manually edit the .csproj file representing your project, this can be accomplished.
For instance, let’s say you have a folder called “binaries” that you need to be copied to the output directory (I recommend using build action of None and Copy to Output Directory Always, but this method can work for either, as I’ll show below).:
Close visual studio, with none of your “binaries” files or folder added. In windows explorer, browse to your project directory, and manually create this “binaries” folder, with the required files. Then, edit the .csproj file for the project with a text editor. Look for a section of the file with several “ItemGroup” tags. You’ll want to make this addition:
When you open the project in Visual Studio again, you will find your inclusions with the correct build action and copy settings.
The same could be done with the Content build action, instead:
However, I’ve had less success using this in the wild.
This is another answer that addresses this issue:
Is there a way to automatically include content files into asp.net project file?