Link to home
Start Free TrialLog in
Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada

asked on

How Can i go from c#7.3 language version to c#10 having already installed Visual Studio 2022

I have a c# project in which i am trying to implement Global Usings. I have Visual studio 2022 installed


I got the error attached suggesting the i should not use c# language Version 7.3

but Version 10 . 

User generated image


 I thought installing  .Net Framework 6.0  would solve the problem but it did not

How do i go from c#7.3 to c# 10


Below find listed the .Net Frame works installed on my system and 6.0 was not one of them

see below

User generated image


How Can i go from c#7.3  language version to c#10  having already installed Visual Studio 2022


Thanks Olukay



Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Microsoft sort of split .NET into two big categories - everything before .NET 5.0 is considered the ".NET Framework" (if you go to create a new project you'll see this in parentheses next to the project type). 


From .NET 5.0 and on, things are just ".NET" or ".NET Core".


So if you're seeing only the 4.x versions in that drop-down field, it means your project is currently a ".NET Framework" project, so you can only go as high as the highest 4.x release.


You can convert from a .NET Framework app to a .NET app in order to move up to .NET 6 (and thus the newer C# language versions) and Microsoft has in-depth walkthroughs on how to do this, depending on your particular type of project.


https://learn.microsoft.com/en-us/dotnet/core/porting/


There's too much to cover in a comment like this but it's worth noting that it's not too difficult to upgrade and most of your code will usually stay the same. MS has tools like the portability advisor and the upgrade assistant to handle almost everything for you. Again, the the documentation above will cover all of that.

You need to upgrade to .net core 6 (go to 7 actually and skip c#10 and go right to 11)

I thought installing  .Net Framework 6.0  would solve the problem but it did not

Which version of .NET did you install? You must use the SDK version in order for it to appear in your Visual Studio. Just installing the runtime is not enough.


For the actual language version the C# compiler uses some defaults:

User generated imageIf you want to override these defaults, you can use the <LangVersion> directive in your project file. For example, you can use one of these


<LangVersion>latest</LangVersion>
<LangVersion>preview<LangVersion>
<LangVersion>11<LangVersion>

Open in new window

You can get more information here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version

.NET 5++ projects have a different project structure.

I'm not aware of a migration tool from .NET Framework 4.8 to .NET 5++. Afaik you need to setup a new project manually and copy your project items.
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Olukayode Oluwole

ASKER

Thank you all

Um, no. ste5an is not correct about copying to a new project nor that there is no tool. I literally referenced the name of the tool in my comment. It's the .NET Upgrade Assistant. It's literally THE tool to help you upgrade from .NET Framework projects to .NET, and it's easy to use. They even have a 3-step walkthrough for it:


.NET Upgrade Assistant | Get Started (microsoft.com) 


Not only can it help upgrade the project but it'll give recommendations on how to change/fix incompatible code. 


You literally open a command prompt, run one command to install the Upgrade Assistant, and then another command to analyze your project, and when ready, one command to do the upgrade.


Here's an example of me analyzing an older project:

User generated image

Again, the Upgrade Assistant is literally designed exactly for doing this kind of task.


Step 1: Open a new, regular Windows command prompt.


Step 2: Install once by running:

dotnet tool install -g --add-source "https://api.nuget.org/v3/index.json" --ignore-failed-sources upgrade-assistant

Open in new window


Step 3: Analyze a project like this:

upgrade-assistant analyze C:\path\to\my\app.sln

Open in new window


Step 4: When ready, upgrade the project:

upgrade-assistant upgrade C:\path\to\my\app.sln

Open in new window


The upgrade will walk you step-by-step through the upgrade process, creating a backup, updating the project definition, swapping out references where applicable, etc...