【问题标题】:Nuget package to copy exe content file to project output directoryNuget包将exe内容文件复制到项目输出目录
【发布时间】:2019-09-12 05:34:01
【问题描述】:

我正在尝试创建一个 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>
    <file src="test.exe" target="lib\net462" />
</files>

使用最后一个配置,尝试将 nuget 包添加到我的 .Net Framework v4.6.2 项目时出现以下异常:

未能添加对“测试”的引用。请确保该文件是可访问的,并且它是一个有效的程序集或 COM 组件。

【问题讨论】:

    标签: c# .net nuget


    【解决方案1】:

    我在 Microsoft 论坛上得到了一个使用 PowerShell 脚本和适用于 Visual Studio 的 PowerShell 工具的有效答案:

    https://social.msdn.microsoft.com/Forums/en-US/cb6236e8-4705-485b-a47c-cc4dc933c92c/nuget-package-to-copy-exe-content-file-to-project-output-directory?forum=visualstudiogeneral

    【讨论】:

      猜你喜欢
      • 2021-04-18
      • 1970-01-01
      • 2019-12-23
      • 2019-01-28
      • 2021-06-16
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2013-02-03
      相关资源
      最近更新 更多