Partager via


Troubleshooting .NET Framework Targeting Errors

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" />

Note

After you close and reopen your project, you should also rebuild it to ensure that all references resolve correctly.

See Also

Tasks

How to: Target a Version of the .NET Framework

Concepts

.NET Framework Client Profile

Other Resources

Targeting a Specific .NET Framework Version or Profile

MSBuild Multitargeting Overview