HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

Upgrade Assistant

Describes the Upgrade assistant, which automates the transition from an ASP.NET Standard project to an ASP.NET Core project.

The Upgrade assistant automates the transition from an ASP.NET Standard project to an ASP.NET Core project. The tool employs the following steps. (You could plug in your own conversion steps.)

  1. Creates a backup
    Upgrade assistant creates a backup because it is going to change important things. You can disable this step if you already have a backup, such as in a source code repository. (Is it possible to choose backup location?)
  2. Identifies solution conversion order
    Upgrade assistant determines and recommends the order to migrate projects within a solution. You can accept the recommendation or decide on another order. See Analyzers.
  3. Runs try-convert
    Upgrade assistant runs the try-convert tool to convert the project file from a cs-style project to an SDK-style project. (are there any configuration options?) The try-convert CLI tool is a standard Microsoft package and is found on GitHub.
  4. Removes transitive NuGet package dependencies
    Old NuGet package dependencies that may have been present in packages.config are removed.
  5. Re-targets project to ASP.NET Core
  6. Updates NuGet packages
    Upgrade assistant updates NuGet packages to versions compatible with ASP.NET Core. A config file uses a list with old package names and versions to map to new package names and versions. If a package is not needed, it is removed. NuGet package references should be .NET Core standard compatible.
    Upgrade assistant removes old packages and transitive dependencies, and then adds new packages. The tool then makes an extra restore to rebuild the lock files. After that, it runs a second pass to look for new transitive dependencies and removes those, just in case new unnecessary transitive dependencies were added by the new NuGet packages. This lets the tool remove redundant packages that were once needed but are unnecessary after the conversion.
  7. Adds template files
    Upgrade assistant adds template files for startup and hosting code that is typically used in Optimizely Content Management System (CMS) environments. You can tweak the template files later. See Startup code.
  8. Migrates app config files
    Upgrade assistant migrates non-C# files, like web.config, using an interface called IConfigUpdater that takes an array of config files and updates them to follow ASP.NET Core standard. You can also implement your own IConfigUpdater by dropping your libraries into a specific folder; they are picked up at runtime and converted. See Application configuration files.
  9. Updates source code
    Upgrade assistant updates the source code by removing unnecessary namespace declarations that are not supported by ASP.NET Core, and adding namespace references that are supported instead.
    Some cases cannot be handled automatically because there may be too many differences between modules, such as converting HTTP modules to middleware. you must manually convert such cases.

When you have run the tool on your solution, the solution will most probably not build until you have manually completed some migration steps. Analyzers are added to help you identify some of the remaining changes needed after the tool runs.

Install the Upgrade assistant

The Upgrade assistant automates common tasks related to migrating ASP.NET MVC and WebAPI projects to ASP.NET Core.

📘

Note

While Upgrade assistant does many of the migration tasks automatically for an ASP.NET project, you will have manual migration tasks to complete the migration.

After you run Upgrade assistant on a project, the project will not build until you complete the migration (because the project is only partially migrated to .NET Core). Analyzers added to the project will highlight some of the remaining changes needed after the tool runs.

The Upgrade assistant is found in an open-source GitHub repository.

The Upgrade assistant is a general migration tool from ASP.NET standard to ASP.NET Core, but it links to another repository, the Optimizely Migrator, that contains code for migrating Optimizely-specific things.

Prerequisites

  • The Upgrade assistant uses MSBuild to work with project files. Make sure that you have a recent version of MSBuild installed. An easy way to do this is to install Visual Studio 2019.
  • This tool requires that your project builds. This may include installing install Visual Studio 2019 to ensure build SDKs (such as for web applications, etc) are available.

To install the Upgrade assistant as a .NET CLI tool:

dotnet tool install -g upgrade-assistant

To upgrade the Upgrade assistant:

dotnet tool update -g upgrade-assistant

To try the latest (and likely less stable) versions of the tool, CI builds are available on the dotnet-tools NuGet feed and can be installed with

dotnet tool install -g upgrade-assistant --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json 

or updated using the same --add-source parameter.

Troubleshoot installation issues

If installation fails, trying running the install command with the --ignore-failed-sources parameter: dotnet tool install -g upgrade-assistant --ignore-failed-sources. Upgrade-assistant is installed as a NuGet package, so invalid or authenticated sources in NuGet configuration can cause installation problems.

Run the Upgrade assistant

📘

Tip

When running the assistant, you access help by typing:

dotnet run -- migrate --help

Use the following command to run the Upgrade assistant:

upgrade-assistant <Path to csproj or sln to migrate>

📘

Note

You can exit the Upgrade assistant in mid-migration and then resume it later. The progress of the migration process is saved to continue where you left off.

Configuration arguments

OptionDescription
--skip-backupBy default, the Upgrade assistant backs up your solution automatically before analyzing and converting your projects. To prevent this, pass this argument. However, you should not do this unless your solution is already in version control.
-b, --backup-path Specifies where the project should be backed up. If you do not specify a backup path, the assistant automatically creates a new directory next to the project directory.
--extension Specifies a .NET Upgrade Assistant extension package to include. This could be an ExtensionManifest.json file, a directory containing an ExtensionManifest.json file, or a zip archive containing an extension. This option can be specified multiple times. describes where the updates come from, or a directory containing a manifest file. You can specify this option multiple times, and you can use this path variable to set multiple paths at the same time UpgradeAssistantExtensionPaths={path1};{path2}.
-e, --entry-point Provides the entry-point project to start the upgrade process. This may include globbing patterns such as '*' for match.
-v, --verboseEnable verbose diagnostics
--non-interactiveAutomatically select each first option in non-interactive mode.
--non-interactive-wait
Wait the supplied seconds before moving on to the next option in non-interactive mode.
--versionShow version information
-?, -h, --helpShow help and usage information

Analyzers

Analyzer functionality is included in the Upgrade assistant to analyze your solution and determine the components that need to be migrated to ASP.NET Core standard. After the analyzers evaluate your code, you can let the Upgrade assistant automatically convert your solution to ASP.NET Core.

Some tasks are not fully automated. For example, the Upgrade assistant does not handle Razor views or CSHTML, but the analyzer functionality does. The analyzer functionality flags non-ASP.NET Core standard with green squiggles directly in the Visual Studio project. You can fix these errors with code quick fix functionality in Visual Studio.

The analyzer also works on an already-converted solution, so when you open your updated ASP.NET Core site in Visual Studio and pull in more code that was not converted to ASP.NET Core standard, the analyzer flags any code that does not follow .NET Core standard (for example, occurrances of System.Web or Owin).

The analyzer tool also works for non-framework libraries, such as business logic libraries.

  • If you have a library that targets ASP.NET Standard and you convert this into ASP.NET Core, it cannot be consumed by ASP.NET Standard anymore.
  • If you have a library with multiple solutions depending on it, other apps targeting this library cannot use it, so in this case you should have a full framework library and then a library specifically for ASP.NET Core code on the side, to make sure shared libraries can still be used by apps not on ASP.NET Core.

Startup code

One challenge with going from ASP.NET Standard to ASP.NET Core is that you no longer have a global.asax file, which let you write code that would run in response to higher "system level" events, such as Application_Start, Application_End, Session_Start, Session_End.

Instead, you have two methods, Configure and ConfigureServices, and a Startup class, and those are significantly different. These cannot be migrated automatically because there are too many app-specific things in global.asax.

At step 5 in the migration process (adding templates), you need four startup files: Program.cs, Startup.cs, appsettings.json, and appsettings.Development.json. If they are missing, Upgrade assistant creates them. It pulls some template files, changes some namespaces (System.Web and Owin are no longer used, and are removed) and then adds them to the project. Your old Startup.cs is saved under the name Startup.old.cs.

In Startup.cs, you can configure services required by the app and define the app's request handling pipeline as a series of middleware components.

Program.cs is often very similar from project-to-project and should not require many changes.

Application configuration files replacing web.config

In previous versions of ASP.NET, web.config stored application configuration settings such as database connection strings, global variables, and so on. In ASP.NET Core, the application configuration settings can come from different configurations sources such as files, user secrets, environment variables, or command-line arguments.

The appsettings.json file stores configuration settings previously found in web.config. If you do not already have appsettings.json in your solution, the Upgrade assistant creates one for you (by adding a template file in step 5) and migrates your web.config settings to this file.

If you had a list of namespaces in web.config that were automatically imported into Razor views, (such as System.Web.Mvc.Html, System.Web.Routing, AlloyTemplates.Models.Pages, and AlloyTemplates.Models.Blocks), you cannot automatically import these namespaces in the views using ASP.NET Core. In ASP.NET Core, you must import them by the _ViewImports.cshtml file instead. Upgrade assistant creates _ViewImports.cshtml and moves the namespaces from web.config to this new file, along with TagHelpers because they can be useful in ASP.NET Core projects. Also, Upgrade assistant does not migrate namespaces starting with System.Web because they are not supported by ASP.NET Core; you should replace them with other namespaces.

The appsettings.{Environment}.json file is a configuration file where {Environment} equals the application's current hosting environments, such as Development, Staging, or Production. This is valuable as you can use different appsettings for different environments.

ExtensionManifest.json

The Upgrade assistant is divided into two repositories. The first one, [], contains the general Upgrade assistant that handles general code conversions from ASP.NET standard to ASP.NET Core. The second repository, [], contains code that is Optimizely specific.

In this second repository, there is an ExtensionManifest.json file which contains the configuration settings for migrating Optimizely-specific code to ASP.NET Core. From the start, it looks something like this, with four sections for different configuration options for the migration steps.

{
  "ConfigUpdater": {
    "ConfigUpdaterPath": "ConfigUpdaters"
  },
  "PackageUpdater": {
    "PackageMapPath": "PackageMaps"
  },
  "TemplateInserter": {
    "TemplateConfigFiles": [
      "Templates\\EPiServerTemplates\\TemplateConfig.json"
    ]
  }
}
  • ConfigUpdater – For any configuration updaters.
  • PackageUpdater – Contains the map file that maps old NuGet packages and versions to new packages and versions.
  • SourceUpdater – For analyzers and code fix providers.
  • TemplateInserter – Contains template files for the Optimizely-specific code, such as Program.cs and Startup.cs.

Related information

If you are just starting to look at .NET Core and want to understand more about potential challenges in migrating any particular project .NET Core, start by looking at .NET Framework dependencies the project has, and third-party libraries or NuGet packages it depends on, and understand whether those dependencies are likely to work on .NET Core. Resources that can help with that analysis include: