Cannot Change Target Framework?

C#

C# Problem Overview


I came across this problem this morning that I can't change the target framework of an open source project. The Target framework option drop down is inactive/disabled. How to make it to work with .NET Framework 2.0?

This is the download link: https://dev.mysql.com/downloads/connector/net/6.10.html

By the way, possible duplicate question? The "Another Question" that had linked is for VS2008. I'm using VS2017, and today's date is 2018. The linked question is about 10 years old. Things changed a lot in 10 years. The solutions provided in that link is almost inapplicable.

Cannot Change Target Framework

C# Solutions


Solution 1 - C#

A modern class library should use multiple target frameworks today, which means the options can only be set in project files right now,

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard1.4;net40;net45</TargetFrameworks>
  </PropertyGroup>

https://docs.microsoft.com/en-us/dotnet/standard/frameworks

Visual Studio does not yet have suitable UI elements to reflect the options, and that's why it is showed the way you saw.

Solution 2 - C#

As @Lex Li has pointed out, VS project properties don't allow you to change the Target Framework, as the project actually targets more than one frameworks. If, however, you plan to target a single framework, you'll have to change the "TargetFrameworks" tag to "TargetFramework" and specify only one target framework. Then, VS will allow you to select it from Project properties page again.

Solution 3 - C#

The two nodes in the project file, TargetFramework and TargetFrameworks (plural) are the culprits. While it didn't help my project by putting net461;net462 into the latter, I tried renaming the nodes to TargetFramework and entered only net461.

The rename logically also gave me back the enabled combobox and that was what Jan was asking.

I changed it back to TargetFrameworks assuming that the other is now decprecated and resolved the "multiple net version"-error by removing the net462-reference and coded a little replacement. I compile but can only target one net-version.

Solution 4 - C#

I am using VS2019 and I got the same issue. I used this Microsoft .NET Framework Repair Tool to fix it. You can download the tool here: https://www.microsoft.com/en-us/download/details.aspx?id=30135 enter image description here

Now I am able to see and change my Target Framework.

Now I am able to see and change my Target Framework.

Solution 5 - C#

In my case deleting the global.json from everywhere, was the solution and fixed all the projects in the whole solution.

Solution 6 - C#

putting this here as well https://github.com/dotnet/project-system/issues/6180 deleting the global.json file in file explorer (not just from the solution), after restarting vs I was able to change the framework

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmjbView Question on Stackoverflow
Solution 1 - C#Lex LiView Answer on Stackoverflow
Solution 2 - C#ArtakView Answer on Stackoverflow
Solution 3 - C#Henrik CarlsenView Answer on Stackoverflow
Solution 4 - C#Junior GrãoView Answer on Stackoverflow
Solution 5 - C#Mohamed MohsenView Answer on Stackoverflow
Solution 6 - C#user1375314View Answer on Stackoverflow