0

I have a nuget package like:

/build/SharedTargets.targets
/content/File.cs

SharedTargets.targets looks like:

<Compile Include="$(MSBuildThisFileDirectory)\..\content\File.cs">
  <Link>File.cs</Link>
  <Visible>True</Visible>
</Compile>

Is there a way how to reference the content files in more elegant way ? I.E. how to construct relative path to content properly.

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89

1 Answers1

3

That's basically how to do it.

I'd suggest not putting .cs files in the content subfolder since they might end up in the project directory on legacy packages.config projects.

If you are only using PackageReference to reference the package, you could use contentFiles instead - a NuGet feature that lets you add files with an associated build action (Compile, EmbeddedResource,...) logically to the build process without needing a .targets file. See Using the contentFiles element for content files for the underlying NuGet mechanism.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217