且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在我的 nuspec 文件中设置“复制到输出目录"属性?

更新时间:2023-09-26 08:12:04

如何在我的 nuspec 文件中设置复制到输出目录"属性?

How can I set the 'copy to output directory' property in my nuspec file?

Martin 指出了正确的方向,我之前也有同样的要求,kjbartel 的回答对我很好.我在此处发布了您的问题的更多详细答案,希望这可以为您提供一些帮助.

Martin pointed out the right direction, I have same request before and kjbartel`s answer is nice to me. I post the answer here with more detail for you question, hope this can give you some help.

要解决此问题,您可以按照以下步骤操作:

To resolve this question, you can follow below steps:

  1. 在你的项目文件夹中添加一个xx.targets文件,确保目标文件的名称与包ID相同(TestDemo是我的包ID,所以.targets的名称是TestDemo.targets).

  1. Add a xx.targets file in your project folder, make sure the name of the target file is the same name as the package id(TestDemo is my package ID, so the name of .targets is TestDemo.targets).

在目标文件中添加以下代码:

Add below code in the targets file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <ItemGroup>
  <None Include="$(MSBuildThisFileDirectory)GRabc.txt">
     <Link>GRabc.txt</Link>
     <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
 </ItemGroup>
</Project>

注意:$(MSBuildThisFileDirectory)"的路径应该是相对路径,不熟悉的可以用绝对路径.

Note: The path of "$(MSBuildThisFileDirectory)" should be relative path, if you are not familiar with it, you can use the absolute path.

  1. 在 nuspec 文件中,将所需文件与目标文件一起添加到 Build 目录中.

  1. In the nuspec file, add required file to the Build directory along with the targets file.

  <files>
    <file src="binx64DebugGR*.txt" target="Build" />
    <file src="TestDemo.targets" target="Build" />
    <file src="binDebugTestDemo.dll" target="lib462" />
  </files>

  • 打包这个包,然后添加到其他项目中测试,效果很好.

  • Pack this package, then add it on other project to test, it work fine.