问题
Currently facing a problem where I have an offline enviroment with Visual Studio on it. Web Application development works fine with my offline Visual Studio installer, absolutely no problems there. But when it comes to MSTest and other things, I seem to be running into issues with missing nuget packages.
As far as I can make out there's no installers that provide these packages (things like Microsoft.VisualStudio etc) and the best way seems to be to let a machine with internet connectivity download the packages during a restore operation and then drag the packages over. But surely this isn't right - Microsoft surely support offline development better than this.
Does anyone have any experience or recommendations with regards to this problem?
回答1:
You should have to create a local nuget package source which stores the related nuget packages. When you use it, you do not need to come to the network to perform the restore operation in the future.
No matter how you realize it, you have to connect to the Internet once to download these packages from Internet into your local disk. After that, you do not need to connect to the Internet for your MSTest projects.
Under Tools-->Options-->Nuget Package Manager-->Package Sources
create a local nuget package source called Local Cache and set a value for it.
In my side, the value is C:\Local Caches
Please do not forget to click Update button.
Then, Please enter nuget.org webiste and download these packages and then copy these nupkg files into the local folder C:\Local Caches
.
Microsoft.NET.Test.Sdk 16.7.1
Microsoft.CodeCoverage 16.7.1
Microsoft.TestPlatform.TestHost 16.7.1
Microsoft.TestPlatform.ObjectModel 16.7.1
NuGet.Frameworks 5.0.0
coverlet.collector 1.3.0
mstest.testadapter 2.1.1
mstest.testframework 2.1.1
system.diagnostics.textwritertracelistener 4.3.0
system.diagnostics.tracesource 4.3.0
Copy them into the local path:
After that, you do not need to connect to Internet when you create the MSTest project.
Every time you faced the loss of nuget packages on your offline environment, you should download the related nuget packages into your local nuget source.
This is the only way for the offline environment, and it is not as convenient as the network environment. Compared with network environment, offline needs to be considered more.
============================
Update 1
Every nuget package has its own nuget dependencies. And its complexity depends on the author of the package, and we have no right to make any changes to it. If you insist on using an offline environment, then you have to do these. Or you could try this which could be more easier: first, delete all nuget cahes under C:\Users\xxx\.nuget\packages
.
Then, connect Internet, open VS, create any projects which you want to use, then build them once.
All of the required nuget packages will store under C:\Users\xxx\.nuget\packages
. The nuget packages which you are used for all project templates are listed under that folder. In this function, you no longer need to manually query their dependencies one by one, and copy all the contents of the packages
folder to the local Local Caches
folder at once. This is more convenient.
来源:https://stackoverflow.com/questions/65294087/is-there-a-better-way-of-downloading-nuget-packages-required-for-net-work-for-a