1
votes

I have a project that targets both .Net 2.0 and .Net 4.5. I built+published it successfully in Visual Studio 2013. The .Net configuration in the .csproj file still says

<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

Yet, when I open the project in VS 2015, it targets .Net 4.5.

I have 2.0 available in the Target Framework dropdown:

Target Framework Dropdown

when I click ".Net Framework 2.0" it gives me a popup saying

Are you sure?

Changing the target framework requires that the current project be closed and then reopened.
Any unsaved changes within the project will be automatically saved.

Changing Target Framework my require manual modification of project files in order to build.

Are you sure you want to change the Target Framework for this project?

When I click yes, the target framework goes back to 4.5 and nothing else happens.

  • I've tried reopening the project and VS, with no luck.
  • I've tried running the .Net 3.5 installer (which apparently includes 2.0), but it says I need to use "Turn Windows Features on/off"
    • I've ensured the .Net 3.5 Windows Feature is enabled.

And now I'm out of ideas. Has anyone else encountered this?

Running Windows 7.

2
Looks like you have been editing the .csproj file with a text editor and it got corrupted. The TargetFrameworkVersion element cannot depend on the Configuration and Platform name. Very visible in your screen-shot, note how the comboboxes are disabled. You can get it built with MSBuild okay, you'll however confuse the stuffing out of the IDE. That wasn't done to make your life more miserable, basic stuff like IntelliSense can't work properly if it doesn't know the target. A rather infamous problem in VS2010 with the Client profile btw. You'll have to re-think your approach. - Hans Passant
@HansPassant, I have a VS2013 project with different build configurations for different target frameworks. Are you saying this is not supported in VS2015? (I understand it is not supported in the GUI) - adrianm
It is not supported in any VS version. It is most obvious when you see what happens when you change the target in the IDE, that's a big massive IDE reset at work. You don't get that reset when you change the selected configuration or platform. How many things will break when you do this is unpredictable, IntelliSense is an obvious casualty. It gets a lot nastier with very well hidden corruption when you use the built-in designers, .resx file corruption in particular can be very hard to diagnose. - Hans Passant

2 Answers

0
votes

In case, the .NET Framework 2.0 is corrupted, use the .NET Framework setup verification tool: https://blogs.msdn.microsoft.com/astebner/2013/11/06/net-framework-setup-verification-tool-and-cleanup-tool-now-support-net-framework-4-5-1/ to verify and once it found any corrupted, you can use the .NET Framework Repair Tool: https://www.microsoft.com/en-us/download/details.aspx?id=30135 to repair it.

Or under ‘Turn Windows Features on or off’, uncheck .NET Framework 3.5 (includes .NET 2.0 and 3.0), then check it.

0
votes

As Hans Passant mentions in the comments, I apparently(?) edited the .csproj to use different frameworks for different configurations. I swear this didn't cause any issues in VS 2013.

But in any case, I verified using ILSpy that the .dll being generated is .Net 2.0, even though the dropdown says 4.5. So I guess all's well that ends well?