【问题标题】:How to make dotnet publish command use private Nuget sources如何使 dotnet publish 命令使用私有 Nuget 源
【发布时间】:2020-05-29 18:30:51
【问题描述】:

我在公司内部使用 VS2019 (16.4)。我更改了 VS Nuget 源代码,我的解决方案在向我们的内部基金会提出多次请求以批准 Nuget 包后编译并运行。

现在我正在尝试使用dotnet publish 命令,但它失败了,出现了一堆错误,例如:error NU1605: Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version.

我认为它可能不知道私有 Nuget 源.....所以我四处搜索,解决方案似乎是在解决方案根目录中包含一个 NuGet.Config 文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Company Artifactory" value="https://repo.comany.com/artifactory/api/nuget/comany-nuget" />
    <add key="Company Eval Artifactory" value="https://repo.comany.com/artifactory/api/nuget/comany-nuget-eval" />
  </packageSources>
</configuration>

这没有帮助。似乎有一个新的dotnet 命令将允许通过 CLI 添加源:https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source 但不幸的是我们的版本是3.1.100,新命令适用于3.1.200...是的...它将召开一次法案大会,以便在我们公司获得新版本。

感谢任何帮助。

【问题讨论】:

  • 还有一个全局 nuget 配置,你也可以添加包源。另外,IIRC,Artifactory 需要自定义访问令牌,你也应该管理它
  • 您可以通过直接修改nuget.config 文件手动完成dotnet nuget 命令所做的几乎所有事情。 dotnet nuget 在幕后实际上并没有做任何其他事情(除了将包上传/删除到 nuget.org)。
  • 谢谢! @omajid 实际上dotnet nuget 是另一件事我没有正确理解。看起来它只有 3 个命令:deletelocalspush。这些都不能帮助我提供 Nuget 资源......我在这里弄错了吗?
  • 正如我在帖子中所说,我们的版本为 3.1.100,不支持新添加的命令 add
  • 我的意思是:3.1.200 有新的dotnet nuget 命令,但据我所知,它们只是修改了nuget.config 文件。您可以手动修改nuget.config 文件,而无需依赖新的dotnet nuget 命令。如果你想添加一个新的源,而不是dotnet nuget add source..,你可以手动在你的nuget.config文件中添加一个&lt;add&gt;元素。

标签: .net-core nuget


【解决方案1】:

感谢@omajid 的帮助。这对我有用:

在每个项目根文件夹中:

  • dotnet restore
  • dotnet build --configuration Release
  • dotnet publish --no-restore -r win-x64 -c Release -o c:\somwhere /p:PublishSingleFile=true /p:DebugType=None

以上要求我们在项目文件中添加运行时标识符:

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
    <AssemblyVersion>0.0.2.0</AssemblyVersion>
</PropertyGroup>

不幸的是,使用运行时标识符进行恢复不起作用(与我原来的问题中的错误相同),这可能意味着项目文件中不需要运行时标识符:
dotnet restore --runtime win-x64

我最初的观察是不正确的! Nuget 源没有导致publish 中的还原问题......它是运行时标识符。我仍然不知道为什么错误会以它的方式表现出来......但是用--no-restore switch 调用dotnet publish 似乎已经为我完成了。

问题仍然是为什么dotnet restore --runtime win-x64 失败。

【讨论】:

    猜你喜欢
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 2014-10-28
    • 2021-08-16
    • 2018-11-01
    • 1970-01-01
    相关资源
    最近更新 更多