0

I created a new .NET Class Library project in .NET Core on Mac OS X. During the project build, I'd like to copy a file into the debug directory. How do I add this to the .csproj file?

.NET Command Line Tools (1.0.1)

Product Information:
Version:            1.0.1
Commit SHA-1 hash:  005db40cd1

Runtime Environment:
OS Name:     Mac OS X
OS Version:  10.12
OS Platform: Darwin
RID:         osx.10.12-x64
Base Path:   /usr/local/share/dotnet/sdk/1.0.1
Set
  • 47,577
  • 22
  • 132
  • 150

1 Answers1

7

As with back to .csproj file the MSBuild is used again, this is can be done by MSBuild items. What you need is to add CopyToOutputDirectory attribute to the corresponding item and specify when to copy (Always, PreserveNewest, Never).

Example of the section in .csproj file (from here):

<ItemGroup>
    <None Include="notes.txt" CopyToOutputDirectory="Always" />
    <!-- CopyToOutputDirectory = { Always, PreserveNewest, Never } -->

</ItemGroup>
Set
  • 47,577
  • 22
  • 132
  • 150
  • Now I'm getting an error: "/code/code.csproj(5,11): error MSB4066: The attribute "Include" in element is unrecognized." –  Jul 13 '17 at 20:30
  • @TrevorSullivan cannot get the same error, could you share more info please? – Set Jul 25 '17 at 05:50
  • I'll see what I can get tomorrow if I can find some time. Thanks –  Jul 25 '17 at 05:52