如何在我的 nuspec 文件中设置“复制到输出目录"属性? [英] How can I set the 'copy to output directory' property in my nuspec file?

查看:26
本文介绍了如何在我的 nuspec 文件中设置“复制到输出目录"属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下 nuspec 文件:

Please consider the following nuspec file:

<?xml version="1.0"?>
<package >
  [SOME METADATA]
  <files>
    <file src="binx64$configuration$GR*.filetype" target="content" />
  </files>
</package>

以上已成功打包以GR"开头的文件类型文件,并将它们添加到我的新参考解决方案中.

The above has successfully packaged up the filetype files starting with 'GR' and has added them to my new, referencing, solution.

问题是我希望这些文件总是被复制到输出目录.我可以通过 nuspec 执行此操作而无需手动修改新解决方案中的属性吗?

The problem is that I want these files to always be copied to the output directory. Can I do this via nuspec without having to manually amend the properties in my new solution?

推荐答案

如何在我的 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.

    这篇关于如何在我的 nuspec 文件中设置“复制到输出目录"属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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