Earlier I mentioned that I've been spending a lot of time using Ubuntu 20.04 in a virtual machine on my MacBook Pro. I've completely switched to Ubuntu when tutoring my computer science students in C, C++, Java, and Python, and use it more and more for .NET5 and C# 9 web application and web API development. Recently I wrote a quick tutorial on how to install .NET5 on Ubuntu 20.04 and now wish to show how to configure the global NuGet.config file in Ubuntu such that you can add additional package sources other than NuGet.org. In this tutorial, I will be adding the Orchard Core Preview feed to NuGet.config so that when I develop custom Orchard Core websites, modules, and themes using the pre-release version of Orchard Core, the pre-release packages used by Orchard Core will automatically be downloaded from the Orchard Core Preview NuGet feed.

NuGet.Config on Ubuntu

When you install the .NET5 SDK on Ubuntu 20.04, a .nuget directory is created, which can be seen using the following commands.

$ cd ~/.nuget
$ ls -1

NuGet
packages

Inside the NuGet directory is a file called NuGet.config that holds a global list of package sources. By default, NuGet.config will only contain a single package source: NuGet.org.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Add Orchard Core Preview Feed to NuGet.config on Ubuntu 20.04

If you're an Orchard Core developer and you wish to develop Orchard Core websites, themes, and modules on Ubuntu 20.04, you will want to modify NuGet.config to include the Orchard Core Preview feed so that the pre-release Orchard Core packages will be found when restoring those packages.

Using Visual Studio Code or other favorite editor, simply add an additional package source for the most recent Orchard Core Preview feed found on CloudSmith. I added it as follows for all of my Ubuntu 20.04 virtual machines. Again, this NuGet feed is for developing Orchard Core websites, themes, and modules using the pre-release (preview) version of Orchard Core.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="OrchardCorePreview" value="https://nuget.cloudsmith.io/orchardcore/preview/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Although I mention the Orchard Core Preview feed in this tutorial, you can add any package source to the NuGet.config file, including custom ones. I have several custom package sources that I use not only for Orchard Core development, but also for ASP.NET Core web application and web API development.

It may not be necessary, but whenever I modify the global NuGet.config file I reboot Ubuntu just to make sure the changes to the package sources and other sections are refreshed going forward. I rarely change it after I add all my custom package sources and settings so this is a file I often change once and only once.

Create an Orchard Core Website

Let's make sure the new Orchard Core NuGet feed on CloudSmith is working by creating a new Orchard Core website using the Orchard Core code generation tools used for developing with the pre-release version of Orchard Core. Orchard Core now uses .NET5 and C# 9 by default and I have .NET5 installed on Ubuntu 20.04 so I can quickly open an Ubuntu shell and create the Orchard Core website using the .NET CLI.

$ dotnet new occms -n Web

Navigate to the Web directory and build the Orchard Core website. If the Orchard Core NuGet feed is found in the global NuGet.config file and working properly, the Orchard Core website should restore the pre-release packages and build the Orchard Core website with zero warnings and errors.

$ cd Web
$ dotnet build

  Determining projects to restore...
  Restored .../Web.csproj (in 1.31 min).
  Web -> .../Web/bin/Debug/net5.0/Web.dll
  Copying translation files: Web

Build succeeded.
    0 Warning(s)
    0 Error(s)

If you get errors, especially timeout errors as the build process unsuccessfully finds Orchard Core packages, double check the NuGet feed you entered for Orchard Core pre-release packages. You may have typed it incorrectly or the NuGet feed mentioned in this Orchard Core tutorial may be out-of-date.

Conclusion

Once you've installed the .NET5 SDK and Orchard Core code generation tools as well as properly configured the global NuGet.config file with the Ochard Core NuGet feed, you should be able to begin developing Orchard Core websites, themes, and modules with preview versions of Orchard Core using Visual Studio Code, JetBrains Rider, or other favorite IDE or editor of your choice on Ubuntu 20.04. Note that much of this will work on other distributions of Linux, too, but I haven't tested it personally.