Update Dotnet CLI and Dependencies to latest Dev bits using MyGet Feed

In this tutorial, we are going to see how we can configure our development environment with the latest Dotnet CLI bits (from Dev branches builds). We will also make sure to pull relevant project dependency bits from MyGet repositories. Developers and organizations tend to maintain stable builds at Nuget repositories where as MyGet is used for nightly Dev builds (in some case unstable versions). The main objective of this tutorial is to demonstrate the flexibility of open source ASP.Net Core (and .Net Core) platforms, through which any developer can get the latest bits of runtimes/frameworks/libraries and can experiment different solutions. Being open source, any developer can identify the defects in the latest bits, report to respective teams and can even suggest a possible fix through pull request (in GIT repository).

NOTE: Beware of the fact that nightly builds might be unstable and can have irregularities in functionality and compatibility. One more important point to watch out is that Visual Studio Tooling might not be available for latest Dev bits (especially for Dotnet CLI). As a result, while running the latest Dotnet version (or its dependencies), Application in Visual Studio might not support certain functionality (like intellisense etc.) or break the regular builds and execution.

Lets get started by configuring our environment with MyGet feeds. Got to the following path in your system – \Users\Your User Name\%AppData%\Roaming\NuGet\NuGet.config. Open the file, it should have something similar to following content.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <disabledPackageSources>
    <add key="Microsoft and .NET" value="true" />
  </disabledPackageSources>
</configuration>

The same configuration file can be opened from Visual Studio. Open Visual Studio –> Tools –> Options –> Nuget Package Manager.

image

Now we can change the packages source (using either of above options) to MyGet Feed of ASP.Net Core Devhttps://dotnet.myget.org/F/aspnetcore-dev/api/v2/.

image

Now go to \Users\Your User Name\.nuget\packages, delete all the packages. For demonstration purpose, I wanted to show the package restore of Microsoft.AspNetCore.Routing. As of today, the stable version of package in Nuget is 1.0.1 and the version in MyGet is 1.1.0-alpha1-22167. Now as we changed our package source to MyGet, we can go ahead and update our applications project.json with below line and save the file. Automatic package restore operation will trigger and we will get the specified package.

"Microsoft.AspNetCore.Routing": "1.1.0-alpha1-22167"

Once restore is completed, we can see the specified package in our project.

image

Lets revert back our package source to Nuget feed and try to restore the new package. We should see an error as shown below because this version of the package it not available in Nuget source.

image

To update to latest version of Dotnet CLI, we can visit the official Github repository – https://github.com/dotnet/cli. Download and install the latest version of SDK (I have downloaded Windows x64 SDK).

image

Once installed, go to global.json file in the ASP.Net Core 1 Application we created and then change it to hold the latest SDK version.

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview3-003686"
  }
}

Then in command line interface, we can check the version which was installed.

image

We make package source pointing to MyGet (as described above) to get all the latest packages. We can now make changes to the applications project.json to fetch latest packages. Following is the dependencies section, not the * which will restore the up to date package from mentioned package source (which is MyGet).

"dependencies": {
  "Microsoft.NETCore.App": {
    "version": "1.0.1",
    "type": "platform"
  },
  "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
  "Microsoft.AspNetCore.Diagnostics": "1.1.0-*",
  "Microsoft.AspNetCore.Mvc": "1.1.0-*",
  "Microsoft.AspNetCore.Razor.Tools": {
    "version": "1.0.0-*",
    "type": "build"
  },
  "Microsoft.AspNetCore.Routing": "1.1.0-*",
  "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0-*",
  "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*",
  "Microsoft.AspNetCore.StaticFiles": "1.1.0-*",
  "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0-*",
  "Microsoft.Extensions.Configuration.Json": "1.1.0-*",
  "Microsoft.Extensions.Logging": "1.1.0-*",
  "Microsoft.Extensions.Logging.Console": "1.1.0-*",
  "Microsoft.Extensions.Logging.Debug": "1.1.0-*",
  "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0-*",
  "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0-*"
}

Now we can try to make Visual Studio restore all the packages. NOTE: Unfortunately at this point, There is a problem with Package restore by Visual Studio. I raised an issue in Dotnet CLI Github Repository - https://github.com/dotnet/cli/issues/4248.

But as I mentioned in the issue (above), I was able to do dotnet restore from command line tool and successfully restore all packages. Before executing the command, I removed all the packages from \Users\Your User Name\.nuget\packages.

image

And once restore is completed, we have following message.

image

After dotnet restore, if we look at Visual Studio Solution, we have references section restored with all mentioned versions of packages.

image

Now we can execute dotnet run.

image

Navigate to the hosted URL (check above output).

image

That’s it for now. Happy Coding and Stay Tuned!!!

You may also like...