visual How do you set up for offline development with.net Core




microsoft net sdk (3)

According to yishaigalatzer (who, according to his Github profile works for "Microsoft" in "Redmond"): "This is by design. Please don't add logic to work around it." (as part of this issue report discussion: https://github.com/NuGet/Home/issues/2623)

So ..

Here are some ways we can then work around it. All of these are intended to stop "dotnet" from trying to connect to the server, and to use the local package directory only:

(1) Add a NuGet.config file as part of your project (in the same directory with project.json) that removes the online repository from the sources. Use the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
    </packageSources>
</configuration>

(2) Use a custom NuGet configuration (eg. "MyCustomNuGet.config") that includes no sources:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>

Then when you run "dotnet restore", explicitly specify to use your custom configuration file:

dotnet restore --configfile MyCustomNuGet.config

(3) When running "dotnet restore", explicitly specify the local package directory as the source:

dotnet restore -s $HOME/.nuget

(or wherever the .nuget directory may be)

Now that everything is based off of nuget packages, how do you do offline development?

Running "dotnet new" and then "dotnet restore" sometimes uses cached packages, and sometimes fails because it can not contact the nuget server.


To setup an offline Ubuntu environment for .Net Core development I've used the following steps: - I've booted a live USB with Ubuntu on a PC connected to Internet and I've installed all necessary packages (dotnet, VS Code, git, node etc.); - From Visual Studio Code I've installed C# extension (and also others if necessary); - I've compiled and ran ASP.Net Core CLI samples with success (this downloaded all NuGet packages nedded); - I've copied on a USB stick all packages caches from: - /var/cache/apt - /home/.../.vscode/extensions - /home/.../.nuget/packages

* instead of ... should be the username

On the offline computer:

  • I've installed all the packages from apt folder with dpkd -i *.deb
  • I've copied Visual Studio extension folders in /home/.../.vscode/extension
    • here I got an error in Visual Studio Code and I had to give permissions on extension folders with chmod -R 777 /home/.../.vscode/extensions
  • I've copied all *.nupkg files from nuget/packages in a new folder (ex. /home/.../mypackages)
    • to copy only the *.nupkg files from nuget/packages cache folder, which is a entire hierarchy of files and folders, I've searched in explorer (Nautilus) ".nupkg" in that cache folder and then copied all the resulted *.nupkg files;
  • Now I've used the dotnet restore command in different projects with the path of Nuget packages: dotnet restore -s $HOME/mypackages

The projects have restored ok and building and debugging in Visual Studio Code is also working ok.

  • working on restoring npm packages cache

Change default nuget cache folder on Linux

You can use the NUGET_PACKAGES env variable to do this, or you can specify --packages at the time you run dotnet restore. The env variable is undocumented, so there could be changes in the future. Here's a link to the relevant code in case that happens: https://github.com/dotnet/cli/blob/rel/1.0.0/build_projects/shared-build-targets-utils/Utils/Dirs.cs#L43

The output of dotnet restore --help will give you more details:

Arguments:
  [root]  List of projects and project folders to restore. Each value can be: a path to a project.json or global.json file, or a folder to recursively search for project.json files.

Options:
  -h|--help                       Show help information
  --force-english-output          Forces the application to run using an invariant, English-based culture.
  -s|--source <source>            Specifies a NuGet package source to use during the restore.
  --packages <packagesDirectory>  Directory to install packages in.
  --disable-parallel              Disables restoring multiple projects in parallel.
  -f|--fallbacksource <FEED>      A list of packages sources to use as a fallback.
  --configfile <file>             The NuGet configuration file to use.
  --no-cache                      Do not cache packages and http requests.
  --infer-runtimes                Temporary option to allow NuGet to infer RIDs for legacy repositories
  -v|--verbosity <verbosity>      The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error.
  --ignore-failed-sources         Only warning failed sources if there are packages meeting version requirement

I would also recommend reading up on this question if you are trying to go for offline development: How do you set up for offline development with .net Core