Nuget包始终使用Release文件夹

标签 nuget

我正在尝试为特定的构建配置创建一个 nuget 包。我们以调试为例。我运行命令:

nuget pack path_to_my.nuspec -属性“Configuration=Debug;”-详细程度

它向我抛出以下错误:

尝试从“path_to_my.nuspec”构建包。 System.IO.FileNotFoundException:找不到文件:'bin\Release\mydll.dll'。

如您所见,它尝试从 bin\Release 获取 dll,而不是 bin\Debug。

是否可以告诉 nuget 使用与 Release 不同的配置,或者使用其他路径?

最佳答案

有必要检查您的 nuspec 文件,以防万一您已将发布路径硬编码为 bin\Release\mydll.dll,情况似乎确实如此。

有效的 nuspec 文件将引用 dll,而无需指定环境。使用通配符允许任何环境。例如:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>MyProject</id>
    <authors>iberodev</authors>
    <version>1.0.0</version>
    <projectUrl>https://www.diegodrivendesign.com/</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Sample</description>
  </metadata>
  <files>
    <file src="bin\*\netstandard2.0/ProjectOne.dll" target="lib\netstandard2.0" />
    <file src="bin\*\netstandard2.0/ProjectOne.pdb" target="lib\netstandard2.0" />
    <file src="bin\*\netstandard2.0/ProjectTwo.pdb" target="lib\netstandard2.0" />
    <file src="bin\*\netstandard2.0/ProjectTwo.pdb" target="lib\netstandard2.0" />
  </files>
</package>

然后运行 ​​nuget pack 命令来引用您的 nuspec。确保您已为正确的环境编译了代码,以便 nuspec 引用的 dll 可用(例如:dotnet build --configuration Debug)

nuget pack ./*NuGet/*.nuspec -Version 1.0.0 -OutputDirectory foo -Prop Configuration=Debug -Verbosity detailed

关于Nuget包始终使用Release文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35163959/

相关文章:

.net - Microsoft.CompilerServices.AsyncTargetingPack 和 Microsoft.Bcl.Async 之间有什么区别?

git - 如何修复丢失的 NuGet 包错误?

带缓存的 NuGet 服务器

NuGet 版本树

c# - 在我的 nuget 包安装后执行一个操作

c# - 无法在 VS2012 上安装 HtmlAgilityPack

visual-studio-code - 从 VS-Code 添加 NuGet 包时出错

c# - 用于共享第 3 方 DLL 的 NuGet 或程序集文件夹?

asp.net - 启用迁移到另一个上下文?

.net-core - Nuget 还原不适用于 Azure Devops 中的工件源