Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Problem: VC++ 2010 SP1 project reference fails when .NET 4.5 installed


View products that this article applies to.

Symptoms

  • Project to project (P2P) references to native VC++ projects are shown in the UI as unresolved (on the “Framework and References” property page). This is indicated by a red exclamation point icon next to the reference name as well as a missing Full Path property.
  • Users that programmatically queue the references (via DTE) will get an empty result or exception.
  • During execution of unit test projects (pressing F5), you get the exception: Exception of type ‘System.Exception’ was thrown

↑ Back to the top


Cause

There was a change in Microsoft.Common.targets between .NET 4.0 and .NET 4.5 that changes the behavior of project to project (P2P) references in Visual Studio 2010. This issue can be caused by any combination of Visual Studio 2010 SP1 and .NET 4.5.

↑ Back to the top


Resolution

Create a text file named "Microsoft.CppBuildEx.targets" that contains the following text:

<!--
***********************************************************************************************
Microsoft.CppBuildEx.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
This file modifies the steps/targets required to build Visual C++ projects.
Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Overrides existing "SetToGetNativeTargetPath" to set 'DesignTimeBuild_GetNativeTargetPath' flag for all C++ projects reference.
SetToGetNativeTargetPath is only called during design time build. -->
<Target Name="SetToGetNativeTargetPath" >
<ItemGroup>
<ProjectReference>
<AdditionalProperties Condition="'%(Extension)' == '.vcxproj'">DesignTimeBuild_GetNativeTargetPath=true</AdditionalProperties>
</ProjectReference>
</ItemGroup>
</Target>
<!-- Overrides existing "GetTargetPath" to return TargetPath if the project is managed or
returns TargetPath if DesignTimeBuild_GetNativeTargetPath is true. -->
<Target Name="GetTargetPath" DependsOnTargets="_DetermineManagedStateFromCL" Returns="@(ManagedTargetPath)" >
<ItemGroup>
<ManagedTargetPath Include="$(TargetPath)" Condition="'$(ManagedAssembly)' == 'true' or '$(DesignTimeBuild_GetNativeTargetPath)' == 'true'" />
</ItemGroup>
</Target>
</Project>


Add the Microsoft.CppBuildEx.targets file to each of these folders (create the folders if needed):

32-bit (x86) Windows:
%ProgramFiles%\MSBuild\Microsoft.Cpp\v4.0\Platforms\Itanium\ImportAfter
%ProgramFiles%\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\ImportAfter
%ProgramFiles%\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\ImportAfter

64-bit (x64) Windows:
%ProgramFiles(x86)%\MSBuild\Microsoft.Cpp\v4.0\Platforms\Itanium\ImportAfter
%ProgramFiles(x86)%\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\ImportAfter
%ProgramFiles(x86)%\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\ImportAfter

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2734667
Revision : 1
Created on : 1/7/2017
Published on : 7/12/2012
Exists online : False
Views : 394