top of page

Migrating to C# 7.3 .NetFramework project

At Viaro Networks, I’m currently working on upgrading the version of .Net Core or the .Net Framework for some projects of one of our clients. To accomplish this task we have to upgrade the C# version, this means we will also need to refactor a lot of code and check the available documentation. We also may need to evaluate the available versions since upgrading could imply changing too much code.

Validate C# 7.3 installation

The first step before doing changes is to test if the C# version that we already implemented in our code, I’ll test C# 7.3 version in an API endpoint. To test it I created this function:



The last function is only supported since C# 7.3 version, I called the function here:



If we have already implemented the version we see in the log files or output window the next message:



If there is an exception we will see the message: “Testing C# 7.3 using a local function: {Error message || nothing}. So you can see the next bullet. “Changes to update to C# 7.3”

You can use these steps to test C# versions. Currently, C# is running version 9 and Net Framework on version 5. Our client is currently using Net Framework 4.8, this is the reason we are migrating to C# 7.3

Changes to update to C#7.3

  • Install Visual Tools 15.0 (if you haven’t done it early), it is already contained in Visual Studio 2017 or the latest version.

  • On your “.csproj” file, you need to change the ToolsVersion to 15.0 (as shown below):



  • Clean and build the solution, if there are syntax errors after the last change you should fix them. Some functions disappear or are optimized with a different name.

  • Important: You need to install Visual Tools 15.0 on your development, QA, and Production server.

  • Important: If you have implement DevOps in your project or solution, make sure to include the version tools, and the “dotnet” word in your compile instructions like this: “dotnet msbuild $projectPath /p:Configuration=$buildConfiguration /t:’Clean;Build’ /p:OutDir=$outDir /p:VisualStudioVersion=15.0

After these changes, you will have completed the upgrade to the new C# version on your project. Remember to test everything again.

Conclusions

  • We need to upgrade our projects to the last version of libraries in order to patch security issues and get better performance.

  • I recommend using the last version of visual studio and the last stable framework to work on new projects, It will save time to migrate after.

References:

  • C# 7.3 documentation: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7

  • C# versions documentation: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version#override-a-default

bottom of page