首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用CLI还原NuGet包?

如何使用CLI还原NuGet包?
EN

Stack Overflow用户
提问于 2020-12-08 22:42:35
回答 1查看 1.4K关注 0票数 0

我正在尝试使用CLI恢复我的项目中的NuGet包。我使用的命令如下所示: NuGet.exe还原解决方案文件-ConfigFile Config文件-NoCache

解决方案文件是我的.sln文件的路径。

配置文件是我的解决方案的NuGet.Config文件夹中的.nuget文件的路径。

当我运行这个命令时,我总是“找不到软件包的版本”。任何更新的包都会发生这种情况。

在同一台机器上,我可以在Visual中打开解决方案,它可以很好地更新包。Visual被设置为使用源:https://api.nuget.org/v3/index.json,它与从CLI中使用的提要相同。不知道为什么它工作从VS,但不是CLI。

更新:我的原始nuget.config如下所示:

代码语言:javascript
复制
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <solution>
        <add key="disableSourceControlIntegration" value="true" />
      </solution>
      <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
      </packageSources>
    </configuration>

我根据佩里的回答把它修改成这个。更新后的配置也得到了相同的结果:

代码语言:javascript
复制
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <config>
    
        </config>
        <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
        </packageSources>
        <packageRestore>
           <add key="enabled" value="True" />
           <add key="automatic" value="True" />
        </packageRestore>
        <bindingRedirects>
           <add key="skip" value="False" />
        </bindingRedirects>
        <packageManagement>
           <add key="format" value="0" />
          <add key="disabled" value="True" />
        </packageManagement>
    </configuration>

将NuGet.exe更新为5.8.0版本,并将详细内容设置为详细并得到以下结果:

代码语言:javascript
复制
NuGet Version: 5.8.0.6930
MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
MSBuild P2P timeout [ms]: 120000
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe "C:\Users\buildadmin\AppData\Local\Temp\NuGetScratch\0bsxh5zl.jlh.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\buildadmin\AppData\Local\Temp\NuGetScratch\wc050pok.qyy.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.29\node_modules\nuget-task-common\NuGet\5.8.0\nuget.exe" /p:RestoreSolutionDirectory="E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\\" /p:RestoreConfigFile="E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\.nuget\NuGet.Config" /p:SolutionDir="E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\\" /p:SolutionName="DsdMobile"
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0113: Google Play requires that new applications must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\Ross.Core.Dex\Ross.Core.Dex.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0114: Google Play requires that application updates must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\Ross.Core.Dex\Ross.Core.Dex.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0113: Google Play requires that new applications must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\Ross.Localization\Ross.Localization.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0114: Google Play requires that application updates must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\Ross.Localization\Ross.Localization.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0113: Google Play requires that new applications must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\Ross.UI\Ross.UI.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0114: Google Play requires that application updates must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\Ross.UI\Ross.UI.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0113: Google Play requires that new applications must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\RossServices\RossServices.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(725,2): warning XA0114: Google Play requires that application updates must use a TargetFrameworkVersion of v8.0 (API level 26) or above. You are currently targeting v5.0 (API level 21). [E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\RossServices\RossServices.csproj]

Restoring NuGet package Plugin.Fingerprint.1.4.9.
Missing C:\Users\buildadmin\.nuget\packages\plugin.fingerprint\1.4.9\plugin.fingerprint.1.4.9.nupkg
WARNING: Unable to find version '1.4.9' of package 'Plugin.Fingerprint'.
  C:\Users\buildadmin\.nuget\packages\: Package 'Plugin.Fingerprint.1.4.9' is not found on source 'C:\Users\buildadmin\.nuget\packages\'.
  https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
  An error occurred while sending the request.
  The request was aborted: Could not create SSL/TLS secure channel.

WARNING: Unable to find version '1.4.9' of package 'Plugin.Fingerprint'.
  C:\Users\buildadmin\.nuget\packages\: Package 'Plugin.Fingerprint.1.4.9' is not found on source 'C:\Users\buildadmin\.nuget\packages\'.
  https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
  An error occurred while sending the request.
  The request was aborted: Could not create SSL/TLS secure channel.

NuGet Config files used:
    E:\TFSBuilds\Agents\AFSDSDHandheld_Agent\_work\40\s\HANDHELD\Android\2.0\2.0.9\.nuget\NuGet.Config

Feeds used:
    C:\Users\buildadmin\.nuget\packages\
    https://api.nuget.org/v3/index.json

我使用VS 2019年,所以我不确定是否需要具体说明。我假设这个问题与“无法创建SSL/TLS安全通道”消息有关,但我不知道如何解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-09 06:15:07

首先,您应该仔细检查nuget.config文件。

对于nuget.config文件来说,这是正确的:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    
    <config>

    </config>
    <packageSources>
            <add key="public feed" value="https://api.nuget.org/v3/index.json"/>
    </packageSources>
    <packageRestore>
       <add key="enabled" value="True" />
       <add key="automatic" value="True" />
   </packageRestore>
   <bindingRedirects>
       <add key="skip" value="False" />
   </bindingRedirects>
   <packageManagement>
       <add key="format" value="0" />
      <add key="disabled" value="True" />
  </packageManagement>

</configuration>

然后是,使用命令nuget restore xxx\ConsoleApp38.sln -ConfigFile "xxx\ConsoleApp38\.nuget\nuget.config" -NoCache,它可以很好地工作。

开头,我在<config></config>下编写任何其他节点,这些节点都会导致与您所说的相同的错误,如下所示:

错误的:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <config>

        <packageSources>
            <add key="public feed" value="https://api.nuget.org/v3/index.json"/>
        </packageSources>

    </config>
</configuration>

之后,我发现<config></config><packageSources></packageSources>具有相同的级别。

您应该按照这份正式文件编写nuget.config文件。

除了,如果你没有计算出你的nuget.config文件,你可以和我们分享它,让我们找到问题。此外,您还可以使用*来替换隐私信息。

更新1

也是,因为您的nuget.exe太老了,对于旧的nuget.exe可能有一些问题。您应该使用我成功测试过的最新nuget.exe v5.8.0。所以请从此链接下载。

更新2

经过进一步的调查,问题更加清楚了。

发送请求时出错。请求被中止:无法创建SSL/TLS安全通道。

您的Internet或网络协议可能有一些问题。如果您使用任何代理,请禁用它。确保你的互联网是纯净的。

此外,如果这没有帮助,请遵循以下建议:

建议

1)以管理员身份打开powershell,运行以下命令:

代码语言:javascript
复制
New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -name 'Enabled' -value '0' -PropertyType 'DWord' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server' -name 'DisabledByDefault' -value 1 -PropertyType 'DWord' -Force | Out-Null
    
New-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client' -name 'Enabled' -value '0' -PropertyType 'DWord' -Force | Out-Null
    
New-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client' -name 'DisabledByDefault' -value 1 -PropertyType 'DWord' -Force | Out-Null
Write-Host 'TLS 1.3 has been disabled.'

reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:64
reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:32

2)使用它打开TSL 1.2

代码语言:javascript
复制
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:32
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:64
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:32
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:64

3),您也可以尝试使用http://packages.nuget.org/v1/FeedService.svc/作为nuget.org源代码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65207993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档