起因:VS2017发布控制台程序时,提示无法读取https://api.nuget.org/v3/index.json,需要认证。
原因:本地机器每次联网时都需要输入用户名和密码。但是发布的时候没有提示框。
解决方案:手动或使用 nuget config -set
将代理设置添加到用户级nuget.config文件
1.若要在包管理器控制台中使用 NuGet CLI 命令,请安装 NuGet.CommandLine 包。
Install-Package NuGet.CommandLine
nuget.exe config -set http_proxy=http://my.proxy.address:port
nuget.exe config -set http_proxy.user=mydomain\myUserName
nuget.exe config -set http_proxy.password=mySuperSecretPassword
执行后的nuget.config文件如下:
<configuration>
<config>
<add key="http_proxy" value="http://my.proxy.address:port" />
<add key="http_proxy.user" value="mydomain\myUserName" />
<add key="http_proxy.password" value="base64encodedHopefullyEncryptedPassword" />
</config>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
nuget.config位置如下: