【问题标题】:How to exclude "AnyCPU" build from NuGet pack?如何从 NuGet 包中排除“AnyCPU”构建?
【发布时间】:2019-04-15 21:51:35
【问题描述】:

我想打包一个仅适用于 x86 和 x64 Windows 的 DLL,因为它可以 PInvokes 到本机 DLL。

我有这个nuspec 文件:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes>First Nuget release</releaseNotes>
    <copyright>$copyright$</copyright>
    <tags>native ugly stuff</tags>
  </metadata>
  <files>
    <file src="bin\Release" exclude="*.dll" />
    <file src="bin\x86\Release\**" target="runtimes/win-x86/lib/net461" />
    <file src="bin\x64\Release\**" target="runtimes/win-x64/lib/net461" />
  </files>
</package>

但是,在运行 nuget pack -Properties Configuration=Release -NoDefaultExcludes 时,AnyCPU 变体仍驻留在生成的包中。

如果我完全删除 AnyCPU 构建目标,我会收到此错误:

Error NU5012: Unable to find 'C:\Users\RabJen\Documents\git\MySolution\MyNativeDLL\bin\Release\MynativeDLL.dll'. Make sure the project has been built.

我错过了什么?

【问题讨论】:

  • 如果您的包仅包含 x86 和 x64 dll,没有其他内容或 contentFiles,您可以尝试将所有 $variables$ 替换为实际值,然后将 nuget pack file.nuspec 替换。如果不打包项目,它不会尝试打包项目输出。
  • 如果我只是对上面的 nuspec 文件执行 nuget pack,它会尝试打包 Debug 版本。
  • nuget pack 将查找 csproj 并将其打包,其中包括获取项目输出。 nuget pack whatever.nuspec 可能不会。
  • 是的,这成功了。我用真实值替换了 $ 的所有内容并运行 nuget pack MyNativeDLL.nuspec

标签: nuget


【解决方案1】:

当您不将文件名传递给 nuget pack 时,它将查找任何 MSBuild 项目文件(如 csproj)、构建它并包含输出程序集。我没有看到任何 options 不包含项目输出。

因此,您最好的选择是明确告诉nuget pack nuspec 文件,例如nuget pack whatever.nuspec。这意味着您的构建脚本需要在打包之前构建项目,因为 NuGet 将不再构建您的项目,并且您还需要将所有变量($'s 包围的任何内容)替换为实际值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 2016-12-21
    • 2013-01-05
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多