nuget包中的.targets文件-如何将内容文件包含到构建中 [英] .targets file within nuget package - how to include content files into a build

查看:605
本文介绍了nuget包中的.targets文件-如何将内容文件包含到构建中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的nuget包:

I have a nuget package like:

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

SharedTargets.targets看起来像:

SharedTargets.targets looks like:

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

有没有一种方法可以更优雅地引用内容文件? IE.如何正确构建内容的相对路径.

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

推荐答案

基本上就是这样做的方法.

That's basically how to do it.

我建议不要将.cs文件放在content子文件夹中,因为它们可能最终出现在旧版package.config项目的项目目录中.

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.

如果仅使用PackageReference来引用程序包,则可以改用contentFiles-NuGet功能,使您可以将具有关联的构建操作(Compile,EmbeddedResource等)的文件逻辑上添加到构建过程中,而无需需要一个.targets文件.请参见使用contentFiles内容文件的元素 用于基本的NuGet机制.

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.

这篇关于nuget包中的.targets文件-如何将内容文件包含到构建中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆