Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

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

Please consider the following nuspec file:

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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. 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).

  2. 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>
    

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

  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>
    
  2. Pack this package, then add it on other project to test, it work fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...