Dotnet 在没有互联网的情况下运行/恢复(离线模式)

use*_*957 4 deployment nuget .net-core

我有一台 Windows 服务器,在其中成功安装并恢复了我的 dotnet core 项目(当时我在服务器上有出站互联网连接)。该应用程序实例现在运行良好。

现在,作为数据中心政策的一部分,出站互联网访问已被撤销。不过,我有 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.
Run Code Online (Sandbox Code Playgroud)

我查了一下C:\Users\xxxxxx\.nuget\packages,所有需要的包都可用。

这两个项目都在相同的 Windows 用户配置文件下运行。

我查阅了有关该主题的各种 Stackoverflow 问题,但它们都讨论了代理设置,这不是我的用例。

由于所有包已在本地缓存中可用,如何防止dotnet查找远程 nuget 服务器。

本地构建 dll 并在服务器上运行是唯一的选择吗?我不能以离线模式在我的服务器上构建它吗?

use*_*957 6

好的。正如通常发生的那样,我在 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  
Run Code Online (Sandbox Code Playgroud)

然后,在 dotnet 恢复期间使用这些源之一

dotnet restore --source C:\Users\bigfo\.nuget\packages\
dotnet build --no-restore
dotnet run --no-restore 
Run Code Online (Sandbox Code Playgroud)