我有一台Windows服务器,我在其中成功安装并恢复了我的dotnet核心项目(当时我在服务器上有出站互联网连接)。这个应用程序实例现在正常运行。
现在,出站互联网访问已被撤销,作为数据中心政策的一部分。不过,我有VPN和远程桌面访问权限。现在,我正在尝试将我的工作项目克隆到一个单独的文件夹中并创建另一个实例(在不同的端口上)。
但是当在我的新项目文件夹上使用dotnet run
时(除了少数设置之外的所有内容都相同),我收到此错误:
$ dotnet run
C:\Program Files (x86)\dotnet\sdk\2.2.102\NuGet.targets(114,5): error :
Unable to load the service index for source https://api.nuget.org
/v3/index.json. [C:\xxxx\xxxx\xxxx.csproj]
C:\Program Files (x86)\dotnet\sdk\2.2.102\NuGet.targets(114,5): error :
A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond [C:\xxxx\xxxx\xxxx.csproj]
The build failed. Please fix the build errors and run again.
我检查了C:\Users\xxxxxx\.nuget\packages
,所有必需的包都可用。
这两个项目都在相同的Windows用户配置文件下运行。
我已经查找了有关该主题的各种Stackoverflow问题,但他们都讨论了代理设置,这不是我的用例。
如何阻止dotnet
查找远程nuget服务器,因为所有软件包都已在本地缓存中可用。
在本地构建DLL并在服务器上运行是唯一的选择吗?我不能在离线模式下在我的服务器上构建它吗?
好。通常情况下,我在SO上发布问题后得到了解决方案。
致谢:https://blog.bigfont.ca/dotnet-restore-without-an-internet-connection/
这是一个简短的说明:
dotnet nuget locals all --list
info : http-cache: C:\Users\bigfo\AppData\Local\NuGet\v3-cache
info : global-packages: C:\Users\bigfo\.nuget\packages\
info : temp: C:\Users\bigfo\AppData\Local\Temp\NuGetScratch
然后,在dotnet恢复期间使用其中一个源
dotnet restore --source C:\Users\bigfo\.nuget\packages\
dotnet build --no-restore
dotnet run --no-restore
您发现的解决方案的替代方法是创建一个删除所有nuget源的nuget.config
文件:
<configuration>
<packageSources>
<clear />
</packageSources>
</configuration>
这样,您不需要使用特殊的命令行参数来还原或构建。