运行该命令
nuget.exe restore .\MySolution.sln
出现以下错误:
无法找到软件包'Microsoft.Net.Compilers'的版本'1.0.0'。
这个软件包先前已被安装和还原,但某种原因导致它已经损坏。
事实证明,只需通过 NuGet 版本更新
nuget.exe update -self
从2.8.0升级到3.4.4就足够了,现在软件包已经能够正确恢复了。
dotnet nuget locals --clear all
后来我成功地恢复了我的软件包:
dotnet restore
我也遇到了同样的问题,但由于无法升级我们的构建服务器上安装的.NET Framework版本(2.8是最后一个与.NET 4.0兼容的版本),因此我需要继续使用nuget.exe
2.8。
问题的原因是只将nuget.config
指向v3 API。解决方案是添加v2 API。例如:
<configuration>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="nuget v2" value="https://www.nuget.org/api/v2" />
</packageSources>
</configuration>
nuget
,但这个方法解决了我的错误。谢谢! - JKennedydotnet cli
时,根据dotnet restore文档,您可以使用dotnet restore
命令,并带有一些选项,如-f
、--no-cache
和--ignore-failed-sources
。dotnet restore -f --no-cache --ignore-failed-sources
C:\Users\<User>\AppData\Roaming\NuGet\
NuGet.config
<packageSources>
中添加 <add key="keyName" value="path to repository">
。在我的情况下,它是指向 \\JENKINS\nuGet Repository
的网络文件夹。<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="local" value="\\JENKINS\nuGet Repository" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
<repository path="..\Common\Luna.Common\packages.config" />
<repository path="..\Common\Luna.ComponentBehaviors\packages.config" />
<repository path="..\Common\Luna.Data\packages.config" />
<repository path="..\Common\Luna.WPF.ApplicationFramework\packages.config" />
<repository path="..\GuyWire\Luna.Basic.GuyWire\packages.config" />
它正在存储信息1.0.0
:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Iesi.Collections" version="3.1.0.4000" targetFramework="net40" />
<package id="log4net" version="2.0.3" targetFramework="net40" />
<package id="NHibernate" version="1.0.0" targetFramework="net40" />
<package id="uNhAddIns" version="1.0.0" targetFramework="net40" />
</packages>
实际上我是按文件引用DLL文件,所以不需要通过NuGet获取。我删除了packages.config
文件,然后错误就解决了。
update -self
命令时,3.3.0版本出现了错误;然后它开始正常工作了。可能是因为旧版本不再受支持。 - Trisped