Using nuget packages on machine with no internet - asp.net-core

I have a .net core intranet web app which uses certain nuget packages. I have two machines, my local computer with internet and a test machine with no connection to outside internet. The app works fine on my computer.
All the nuget packages are locally stored and referred by the web app.
When I try to build the app on test machine, I am getting the following error
C:\Program Files\dotnet\sdk\3.0.100\Nuget.targets(123,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json
What process is actually looking for service index from outside url? Of course it cannot find because there is no internet. No proxies involved so nothing to put in nuget.config
All the packages are locally stored. What can I do to resolve this issue?
Thank you

You’ll need a local folder to keep all your local NuGet packages..
Then download the NuGet packages you wish to be able to use offline into this folder. Packages can be downloaded from nuget.org.
Once you are logged in, search for the packages you require and click the ‘Download’ link in the left hand menu of each.
Once you have successfully downloaded the .nupkg files you require into your local repository folder, head into Visual Studio and open the NuGet Settings dialog via Tools > NuGet Package Manager > Package Manager Settings. Click the Package Sources tab within the settings dialog, followed by the ‘plus’ icon in the top left to add a new package source.
Enter the Name and Source of your local repository. The name can be any string and will be the name displayed in the NuGet Package Manager within Visual Studio.
Now that you have added the local package source, you will be able
to use your offline local repository from within Visual Studio in
the usual way, either via the Console or via the Package Dialog, by
selecting it from the Package Source menu, without the need for an active internet connection.

Related

IronPDF - Use different nuget source for downloading platform specific dependencies

Our dev environment is behind Firewall and default NuGet url is blocked and we use a custom NuGet repo url for downloading package.
IronPdf tries to download IronPdf.Native.Chrome.Windows version 2022.2.4868 in runtime from https://www.nuget.org/api/v2/package/IronPdf.Native.Chrome.Windows/2022.2.4868 which is blocked and returns error message saying Failed downloading NuGet package at runtime
I have tried manually adding that package to the project but it is still not included in the build output and IronPdf again tries to retrieve from NuGet
How to
Include the Native package in deployed output
OR
Configure NuGet source in IronPdf
As the comment under your post suggests, this is most likely a permission issue with your temp or bin directory where IronPdf is attempting to deploy the dependencies it extracts from that package.
In our case, IronPdf was attempting to deploy the Chrome dependencies to, \runtimes\win-64x\native, in our deployment directory. We use service accounts for our IIS App Pool Identities, so we gave full permissions over the entire deployment (web) directory where the IIS Web Site is pointing to and the issue was resolved.

Download Nuget Packages for Offline Development/Publishing

Short Question
Is there a way to programmatically download all of the Nuget packages needed to build/publish a solution and output them into a single directory that can be moved to a local Nuget repository?
Some Background
Where I work, most development is done on an air-gapped network (no internet). On a recent project, I was able to develop on our internet-enabled network. This happens to be the first application developed on the internet-enabled network and the first ASP.NET Core app we've ever developed. The solution builds, runs, and publishes just fine on the internet-facing network. I am now trying to move the solution to the air-gapped network, but I am having issues getting all of the dependencies moved over.
At first, the solution wouldn't build because of missing ASP.NET Core nuget packages; so I copied ALL of the nuget packages from the local cache on the machine that I used to develop the application to the local Nuget repository on the air gapped network. Now the application builds, but I can't seem to publish the web project (ASP.NET Core). I'm getting 25+ errors along the lines of:
Unable to find package runtime.any.System.Diagnositics.Tools. No packages exist with this id in source(s)...
Unable to find Nicrosoft.NETCore.App with version (>= 2.1.6)...
Unable to find...
I'm also getting a runtime error "This page cannot be displayed" when I try to run from visual studio (using IIS Express), but I'm not sure if that's a related issue. The unit/integration tests run fine.
I could try manually downloading each nuget package from Nuget.org and moving them over to the air gapped network, but it takes hours to get things moved from one network to another. Is there anyway I can automate the retrieval of all nuget packages required to build/publish a solution so that I can make a single transfer from one network to the other instead moving what I have and waiting to see what breaks? Preferably I'd like a exe or a PowerShell script that could look at a sln file and drop all the necessary nuget packages into a specified directory.
On your internet enabled dev env, you can browse to the root directory of your project and use:
dotnet restore --packages .\package\
This will use the directory called 'packages' as the local cache for the solution and all nuget files will be copied to it.
You can then include the same switch in your build, to ensure that the local cache is used.
dotnet build --packages .\package\
I answered two very similar questions a few weeks ago. Have a look at these answers to see if they help
Command to download a Nuget package with all dependencies to a folder
Is it possible to create a cache of nuget packages for computers without internet?

VB.NET Azure deployment has no /bin but has a nuget package

I've just published (via GitHub) a VB.NET Azure Website that works fine on local machines but not on Azure:
Compiler Error Message: BC30451: 'Newtonsoft' is not declared. It may
be inaccessible due to its protection level.
Dim category As Category = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Category)(json)
The Newtonsoft.Json package is installed via NuGet: Newtonsoft.Json.5.0.5.
It's the only 3rd party dll in the project right now.
I used the Azure ftp access to browse to /site/wwwroot/ and noticed that there is no /bin directory.
Now, my .gitignore excludes [Bb]in and [Oo]bj folders, but it's the same .gitignore I've used successfully with c# projects and always assumed that Azure just fetches the missing nuget dlls from /packages.
This is my first VB.NET > GitHub > Azure Websites deployment. What have I missed?
edit: I can confirm that if I upload /Bin/Newtonsoft.Json.dll via Azure ftp the site works. Or at least it will until it's re-imaged...
Sounds like you've not enable "NuGet Package Restore".
By doing so this creates a .nuget folder at the root of your solution and a packages.config file in the application that the build process in Azure will pick up and load the required references from.
Right click on the solution and it should be an option in there.

During build/deploy, how do I get around Nuget packages that only copied files?

Background
I have an MVC3 project to which I added the Twitter.Bootstrap.Less Nuget package.
To my knowledge, all this did was copy the appropriate JavaScript / LESS files into their appropriate directories.
However, when I now run this through my build/deploy process onto my dev server, MSBuild doesn't copy the /Content/less folder to my production server as part of deployment package.
My build server doesn't have an internet connection, so unfortunately using NuGet without committing packages to source control isn't an option.
Question
How do I get MSBuild to deploy these files? Or do I need to copy the files, uninstall the nuget package, and manually copy them back in?
You could setup your own internal NuGet package source. That would be internal to your network and mean the build server could pickup the NuGet packages without an internet connection.
E.g. On the server, copy the packages you need to a folder and setup a package feed to that folder for the build server to use.
See:
http://docs.nuget.org/docs/creating-packages/hosting-your-own-nuget-feeds

How to Create Websetup for Clickonce type windows forms application by publishing it to some folder

Trying to publish a click once type app to a local directory and create a websetup with the published contents- so that i can give tat setup to install in two different servers. but as the publishing wizard takes a URL - separate setup is required for each server. Is there any way that i can create a single setup which i can use it in two servers..?
The URL for setup.exe is only for the purpose of bootstrapping. What I found is that the bootstrapper that gets created with your deployment manifest ('setup.exe') is designed for a web-published application.
If your clickonce publish will be installed on intranet servers, you can't use out of the box bootstrapper. You may write your own or build a seperate setup project for bootstrapping and calling the .application from the installed server when the pre requisites where installed.
If you don't rely on pre requisites and you can ask users to make sure they have the right CLR version, you don't need the setup.exe at all.