Migrating to C# 7.3 .NetFramework project

May 13, 2021Code , Development , Tech , Technology , Tutorial

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 in 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:

 


Related post

Implementing a Live Streaming feature on your site with C# .Net Core and AWS

Code , Development , Technology

These days, Live Streaming services are causing a great impact in terms of staying connected with other people, now during this pandemic, the technologies we have are capable of serving these needs. In this post, I want to describe a few points and recommendations about which technologies we can use to embed your existing live-streaming …

Read more
What to look for when hiring a software developer from an outsourcing company?

Development , Outsourcing , Technology

There are some key factors to consider when hiring a software developer from an outsourcing company. Outsourcing has become a common practice, especially when it comes to software development since it provides a cost-effective solution when hiring process developing talent. Although you will avoid the usual pains of the hiring process, it’s always good to …

Read more

Leave A Comment

Your email is safe with us.