Skip to main content

Using the .NET Upgrade Assistant to upgrade a Windows Forms App–Part I

About 10 years ago I was part of a team that created a rather big Windows Forms application. It took us over 2 years to build the application and at that time it was the largest application I had ever built(to give you an idea, the requirements document was over 1000 pages). Today, 10 years later, this application is still in use and recently I was requested to help introduce a new module in this application.

As Windows Forms got ported to .NET Core, I thought it would be a good idea to to see if I could easily port this application to .NET Core. Microsoft created the .NET Upgrade Assistant exactly for use cases like this.

Install the .NET Upgrade Assistant

The .NET Upgrade assistant is available as a global tool and can be installed with the following command:

dotnet tool install -g upgrade-assistant

Analyze your app before upgrading

As the real migration process can take up a lot of time, the .NET Upgrade Assistant tool includes an analyze mode that performs a simplified dry run of upgrading your app. This already gives you a good idea on what changes may be required before the upgrade is started and what could be possible show-stoppers.

We open up a terminal and browse to the solution folder of our application. There we execute the following command:

upgrade-assistant analyze <solutionname>.sln

Here is the output for our application:

C:\projects\DOG\Main\Source\VLM.DOG>upgrade-assistant analyze vlm.dog.sln

-----------------------------------------------------------------------------------------------------------------

Microsoft .NET Upgrade Assistant v0.3.310801+057ffba0656270dc5d83c015748ac56daed55886

We are interested in your feedback! Please use the following link to open a survey: https://aka.ms/DotNetUASurvey

-----------------------------------------------------------------------------------------------------------------

[20:46:23 INF] Loaded 6 extensions

Telemetry

----------

The .NET tools collect usage data in order to help us improve your experience. The data is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_UPGRADEASSISTANT_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about Upgrade Assistant telemetry: https://aka.ms/upgrade-assistant-telemetry

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

[20:46:25 INF] Using MSBuild from C:\Program Files\dotnet\sdk\6.0.300\

[20:46:25 INF] Using Visual Studio install from C:\Program Files\Microsoft Visual Studio\2022\Professional [v17]

[20:46:32 INF] Writing output to C:\projects\DOG\Main\Source\VLM.DOG\AnalysisReport.sarif

[20:46:32 INF] Marking assembly reference System.ServiceModel for removal based on package mapping configuration System.ServiceModel

[20:46:32 INF] Adding package System.ServiceModel.Primitives based on package mapping configuration System.ServiceModel

[20:46:32 INF] Adding package System.ServiceModel.Http based on package mapping configuration System.ServiceModel

[20:46:32 INF] Adding package System.ServiceModel.Duplex based on package mapping configuration System.ServiceModel

[20:46:32 INF] Adding package System.ServiceModel.NetTcp based on package mapping configuration System.ServiceModel

Remark: I have only pasted a small subset of the output. If you are interested in the full log file, have a look here.

Some interesting things to notice in the logs:

  • The upgrade-assistant installs Roslyn Analyzer packages in your projects. These packages do the real work of analyzing your application.
  • The Microsoft.Windows.Compability nuget is added as well to extend the API surface of .NET Standard 2.0 and introduce a set of missing API’s and functionality.
  • The upgrade analyzer recommends to use the net6.0-windows target framework moniker (TFM). This is because the projects referenced by the solution are Windows Forms projects, a Windows-only technology.
  • I got some ‘Diagnostic UA0002 with the message This type is not supported on .NET Core/.NET 5+ and should be replaced with a modern equivalent’ messages with no clear indication on the type the message was refering to.
  • I got some ‘Diagnostic UA0013_I with the message Windows Forms Deprecated controls : Microsoft.Reporting.WinForms.ReportViewer is no longer supported’ messages indicating that I could no longer use the ReportViewer control.

I also got 2 types of warnings:

  • One type of warnings was related to a Detected package downgrade:
[WRN] [NuGet] Detected package downgrade: System.ServiceModel.Security from 4.9.0 to 4.8.1. Reference the package directly from the project to select a different version. project -> Microsoft.Windows.Compatibility 6.0.0 -> System.ServiceModel.Security (>= 4.9.0) project -> System.ServiceModel.Security (>= 4.8.1)
  • The other one was related to the HighDPI mode in WinForms:

[WRN] HighDpiMode needs to set in Main() instead of app.config or app.manifest - Application.SetHighDpiMode(HighDpiMode.<setting>). It is recommended to use SystemAware as the HighDpiMode option for better results.

We'll have a look on how to get rid of these messages before we start the upgrade. But I'll leave that for another post.

Popular posts from this blog

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...

Podman– Command execution failed with exit code 125

After updating WSL on one of the developer machines, Podman failed to work. When we took a look through Podman Desktop, we noticed that Podman had stopped running and returned the following error message: Error: Command execution failed with exit code 125 Here are the steps we tried to fix the issue: We started by running podman info to get some extra details on what could be wrong: >podman info OS: windows/amd64 provider: wsl version: 5.3.1 Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM Error: unable to connect to Podman socket: failed to connect: dial tcp 127.0.0.1:2655: connectex: No connection could be made because the target machine actively refused it. That makes sense as the podman VM was not running. Let’s check the VM: >podman machine list NAME         ...