This article will talk about how you can easily upgrade your .Net Framework solution to .Net 5 (6, Core, Standard).
Microsoft released a simple dotnet script to do this painful task for you.
Currently the tool supports the following .NET Framework app types:
- .NET Framework Windows Forms apps
- .NET Framework WPF apps
- .NET Framework ASP.NET MVC apps
- .NET Framework console apps
- .NET Framework class libraries
First, you need to have .Net SDK installed, the tool dotnet, and of course Visual Studio (2019 or up).
If your solution is a bit old, you should maybe open it in Visual Studio and update all the NuGet packages to the latest version and eventually adapt the code according to these dependencies. Because let’s say you are using a package called Polly v5 and the latest version is 7, you might need to do some changes. This step is pretty important to avoid a big mess later on, because the upgrade script will update all your NuGet packages for you. So better be ready for the changes.
Open a command prompt (CMD) and then install the try-convert dependency:
dotnet tool install -g try-convert
Code language: C# (cs)
Ok, let’s install the upgrade-assistant:
dotnet tool install -g upgrade-assistant
Now you’re ready to upgrade your solution or your project(s):
upgrade-assistant upgrade <Path to csproj or sln to upgrade>
Code language: HTML, XML (xml)
So for example you could have something like:
upgrade-assistant upgrade .\WpfTest.csproj
Now the tool will show you a list of options. Basically you will have to upgrade each project one by one and step by step:
All you have to do is to type 1 and enter, and follow the steps…
To resume the steps:
- Select the project
- Backup
- Convert to SDK style
- Update TFM
- Update NuGet packages
- Migrate the config file
- Update the code
- Go to the next project
When everything is done, open your solution in Visual Studio and check if you can build. You might want to verify the config file as well because it will be migrated to a appsettings.json file. So if you were using ConfigurationManager.AppSetting, you will need to do some adaptations as well.
If you are using Entity Framework, it’s a good time to migrate to EF Core too. The changes are not that complicated.
Happy coding! 🙂