![](/img/trans.png)
[英]Copy nuget package content file (of type .exe) to output directory of project using that nuget package
[英]Nuget package to copy exe content file to project output directory
我正在尝试创建一个Nuget包,该包会将可执行文件复制到.Net框架库的输出目录。
这是我的nuspec文件:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>CopyExeToOutputNugetPackage</id>
<version>1.0.0</version>
<authors>Some Dude</authors>
<owners>Some Owner</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A package to copy an exe to the output directory.</description>
<tags>CopyExeToOuput</tags>
<contentFiles>
<files include=".\content\test.exe" buildAction="None" copyToOutput="true" />
</contentFiles>
</metadata>
</package>
“ nuget pack”命令可以正常工作并构建我的.nupkg文件。 然后,我可以将nuget项目添加到我的.Net Framework项目中,并将test.exe文件添加到我的项目中:
<ItemGroup>
<Content Include="test.exe" />
</ItemGroup>
然后,我可以使用Visual Studio编辑文件属性以复制到输出目录,并更新我的项目文件:
<ItemGroup>
<Content Include="test.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
我希望不需要最后一个手动步骤。
我尝试使用.targets文件,但这是错误的路径,或者我从未正确配置。
我也尝试使用nuspec files元素(而不是):
<files>
<file src="test.exe" target="lib\net462" />
</files>
使用这种最后的配置,当尝试将nuget包添加到我的.Net Framework v4.6.2项目时,出现以下异常:
无法添加对“测试”的引用。 请确保该文件可访问,并且它是有效的程序集或COM组件。
在Microsoft论坛上,我得到了一个有效的答案,该答案使用PowerShell脚本和Visual Studio的PowerShell工具:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.