onlyforbopi
3/9/2018 - 1:39 PM

CSharp.Frameworks

Windows / Version - Framework Correspondence. How to target specific framework upon creation How to change framework Troubleshooting Framework Errors

Troubleshooting .NET Framework Targeting Errors
Visual Studio 2015 Other Versions 
 
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see Troubleshooting .NET Framework Targeting Errors on docs.microsoft.com. This topic describes MSBuild errors that might occur because of reference issues and how you can resolve those errors.

You Have Referenced a Project or Assembly That Targets a Different Version of the .NET Framework
You can create applications that reference projects or assemblies that target different versions of the .NET Framework. For example, you can create an application that targets the client profile for the .NET Framework 4 but references an assembly that targets the .NET Framework 2.0. However, if you create a project that targets an earlier version of the .NET Framework, you can’t set a reference in that project to a project or assembly that targets the client profile for the .NET Framework 4 or the .NET Framework 4 itself. To resolve the error, make sure that your application targets a profile or profiles that are compatible with the profile that’s targeted by the projects or assemblies that your application references.

You Have Re-Targeted a Project to a Different Version of the .NET Framework
If you change the target version of the .NET Framework for your application, Visual Studio changes some of the references, but you may have to update some references manually. For example, one of the previously mentioned errors might occur if you change an application to target the .NET Framework 3.5 Service Pack 1 and that application has resources or settings that rely on the client profile for the .NET Framework 4.

To work around application settings, open Solution Explorer, choose Show All Files, and then edit the app.config file in the XML editor of Visual Studio. Change the version in the settings to match the appropriate version of the .NET Framework. For example, you can change the version setting from 4.0.0.0 to 2.0.0.0. Similarly, for an application that has added resources, open Solution Explorer, choose the Show All Files button, expand My Project (Visual Basic) or Properties (C#), and then edit the Resources.resx file in the XML editor of Visual Studio. Change the version setting from 4.0.0.0 to 2.0.0.0.

If your application has resources such as icons or bitmaps or settings such as data connection strings, you can also resolve the error by removing all the items on the Settings page of the Project Designer and then re-adding the required settings.

You Have Re-Targeted a Project to a Different Version of the .NET Framework and References Do Not Resolve
If you retarget a project to a different version of the .NET Framework, your references may not resolve properly in some cases. Explicit fully qualified references to assemblies often cause this issue, but you can resolve it by removing the references that do not resolve and then adding them back to the project. As an alternative, you can edit the project file to replace the references. First, you remove references of the following form:

<Reference Include="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />  

Then you replace them with the simple form:

<Reference Include="System.ServiceModel" />  
Changing the target version
You can change the targeted version of the .NET Framework in a Visual Basic, Visual C#, or Visual F# project by following this procedure.

To change the targeted version
In Solution Explorer, open the shortcut menu for the project that you want to change, and then choose Properties.

Visual Studio Solution Explorer Properties

System_CAPS_ICON_important.jpg Important
For information about how to change the target version for C++ projects, 
see How to: Modify the Target Framework and Platform Toolset.

In the left column of the properties window, choose the Application tab.

Visual Studio App Properties Application tab

System_CAPS_ICON_note.jpg Note
After you create a Windows Store app, you can't change the targeted version 
of either Windows or the .NET Framework.

In the Target Framework list, choose the version that you want.

In the verification dialog box that appears, choose the Yes button.

The project unloads. When it reloads, it targets the .NET Framework version that you just chose.

System_CAPS_ICON_note.jpg Note
If your code contains references to a different version of the .NET Framework than the one 
that you targeted, error messages may appear when you compile or run the code. To resolve 
these errors, you must modify the references. See Troubleshooting .NET Framework Targeting Errors.
How to: Target a Version of the .NET Framework
Visual Studio 2015 Other Versions 
 
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at How to: Target a Version of the .NET Framework.

This document describes how to target a version of the .NET Framework when you create a project and how 
to change the targeted version in an existing Visual Basic, Visual C#, or Visual F# project.

For information about how to change the target version for C++ projects, see 
How to: Modify the Target Framework and Platform Toolset.

Targeting a version when you create a project

Targeting a version when you create a project
When you create a project, the version of the .NET Framework that you target determines which templates 
you can use.

In Express editions of Visual Studio, you must create the project first, and then you can change the 
target, as Changing the target version describes later in this topic.

To target a version when you create a project
On the menu bar, choose File, New, Project.

In the list at the top of the New Project dialog box, choose the version of the .NET Framework that 
you want your project to target.

System_CAPS_ICON_note.jpg Note
Typically, only one version of the .NET Framework is installed with Visual Studio. If you want to 
target another version, you must first make sure that it's installed. See Visual Studio Multi-Targeting 
Overview.

In the list of installed templates, choose the type of project that you want to create, name the project, 
and then choose the OK button.

The list of templates shows only those projects that are supported by the version of the .NET Framework 
that you chose.
Answer:

Over the past few months, I've received several variations on this question for other operating systems and all of the released versions of the .NET Framework.  When the .NET Framework is installed as a part of the OS, it does not appear in the Programs and Features (or Add/Remove Programs) control panel.  The following is a complete list of which version of the .NET Framework is included in which version of the OS:

Windows XP Media Center Edition (Windows XP SP1) includes the .NET Framework 1.0 + SP2 as an OS component
Windows XP Media Center Edition (Windows XP SP2 and higher) includes the .NET Framework 1.0 + SP3 as an OS component.  On Windows XP Media Center Edition, the only way to get the .NET Framework 1.0 SP3 is to install Windows XP SP2 or higher.  There is not a standalone 1.0 SP3 installer for this edition of Windows XP.
Windows XP Tablet PC Edition (Windows XP SP1) includes the .NET Framework 1.0 + SP2 as an OS component
Windows XP Tablet PC Edition (Windows XP SP2 and higher) includes the .NET Framework 1.0 + SP3 as an OS component.  On Windows XP Tablet PC Edition, the only way to get the .NET Framework 1.0 SP3 is to install Windows XP SP2 or higher.  There is not a standalone 1.0 SP3 installer for this edition of Windows XP.
Windows Server 2003 (all x86 editions) includes the .NET Framework 1.1 as an OS component; 64-bit versions of Windows Server 2003 do not include a version of the .NET Framework as an OS component
Windows Vista (all editions) includes the .NET Framework 2.0 and 3.0 as OS components  3.0 can be added or removed via the Programs and Fatures control panel.
Windows Vista SP1 (all editions) includes the .NET Framework 2.0 SP1 and 3.0 SP1 as OS components.  3.0 SP1 can be added or removed via the Programs and Features control panel.
Windows Server 2008 and Windows Server 2008 SP1 (all editions) includes the .NET Framework 2.0 SP1 and 3.0 SP1 as OS components.  The .NET Framework 3.0 SP1 is not installed by default and must be added via the Programs and Features control panel though.
Windows Server 2008 SP2 (all editions) includes the .NET Framework 2.0 SP2 and 3.0 SP2 as OS components.  The .NET Framework 3.0 SP2 is not installed by default and must be added via the Programs and Features control panel though.
Windows Server 2008 R2 (all editions) includes the .NET Framework 3.5.1 as an OS component.  This means you will get the .NET Framework 2.0 SP2, 3.0 SP2 and 3.5 SP1 plus a few post 3.5 SP1 bug fixes.  3.0 SP2 and 3.5 SP1 can be added or removed via the Programs and Features control panel.
Windows 7 (all editions) includes the .NET Framework 3.5.1 as an OS component.  This means you will get the .NET Framework 2.0 SP2, 3.0 SP2 and 3.5 SP1 plus a few post 3.5 SP1 bug fixes.  3.0 SP2 and 3.5 SP1 can be added or removed via the Programs and Features control panel.
Windows 8 (all editions) includes the .NET Framework 4.5 as an OS component, and it is installed by default.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Programs and Features control panel.
Windows 8.1 (all editions) includes the .NET Framework 4.5.1 as an OS component, and it is installed by default.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Programs and Features control panel.
Windows Server 2012 (all editions) includes the .NET Framework 4.5 as an OS component, and it is installed by default except in the Server Core configuration.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Server Manager.
Windows Server 2012 R2 (all editions) includes the .NET Framework 4.5.1 as an OS component, and it is installed by default except in the Server Core configuration.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Server Manager.
Windows 10 (all editions) includes the .NET Framework 4.6 as an OS component, and it is installed by default.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Programs and Features control panel.
Windows 10 November 2015 Update (all editions) includes the .NET Framework 4.6.1 as an OS component, and it is installed by default.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Programs and Features control panel.
Windows 10 Anniversary Update (all editions) includes the .NET Framework 4.6.2 as an OS component, and it is installed by default.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Programs and Features control panel.
Windows Server 2016 (all editions) includes the .NET Framework 4.6.2 as an OS component, and it is installed by default except in the Server Core configuration.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Server Manager.
Windows 10 Creators Update (all editions) includes the .NET Framework 4.7 as an OS component, and it is installed by default.  It also includes the .NET Framework 3.5 SP1 as an OS component that is not installed by default.  The .NET Framework 3.5 SP1 can be added or removed via the Programs and Features control panel.
Note - for the .NET Framework 2.0, 3.0 and 3.5, you can see a graphical view of the above information in this blog post.

In addition, the .NET Framework shipped with the following versions of Windows but not as truly integrated OS components:

Windows XP Home and Professional SP1 includes the MSI-based .NET Framework 1.0 + SP2 in the Additional Components folder on the installation CD.  It is not an OS component on this OS.
Windows XP Home and Professional SP2 includes the MSI-based .NET Framework 1.1 + SP1 in the Additional Components folder on the installation CD.  It is not an OS component on this OS.
Windows XP Home and Professional SP3 includes the MSI-based .NET Framework 1.1 + SP1 in the Additional Components folder on the installation CD.  It is not an OS component on this OS.
Windows Server 2003 R2 includes the MSI-based .NET Framework 2.0.  It appears in Add/Remove Windows Components as an OS component, but selecting it simply invokes the MSI-based installer.  The MSI can be repaired and removed using Add/Remove Programs regardless of whether it is installed via the standalone MSI or via the Add/Remove Windows Components UI.