我在公司内部使用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://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source 但不幸的是我们的版本是3.1.100
,新命令适用于3.1.200
......是的。。。需要法案国会才能在我们公司获得新版本。
任何帮助,不胜感激。
感谢@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
开关打电话给dotnet publish
似乎已经为我做到了。
问题仍然是为什么dotnet restore --runtime win-x64
失败了。