.targets file within nuget package - how to include content files into a build

别说谁变了你拦得住时间么 提交于 2019-12-13 04:09:15

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/55286717/targets-file-within-nuget-package-how-to-include-content-files-into-a-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!