Including content files in .csproj that are outside the project cone

I believe @Dmytrii gets it right on one hand – you want to use the “link” feature.

However, he’s only partly correct when saying you can’t link to a directory tree.
While this is, indeed, true when trying to add the links using Visual Studio’s GUI, MSBuild supports this.

If you want to preserve the directory structure, just add the %(RecursiveDir) tag to your <link> node:

<Content Include="..\..\MyContentFiles\**\*.*">
  <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

The page MSBuild Well-known Item Metadata goes into more detail on the metadata you can access.

Leave a Comment