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.