Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using MSBuild with VS2010-generated vcxproj file as target -- error MSB4066 ("attribute Label in element is unrecognized")

Using VS2010, I created a Win32 C++ console application called "TfsBuildTestTarget". This is just the default console application created by the wizard. I made no code or project changes, and it builds ok in VS2010 as expected.

Then I created an MSBUILD project file as follows:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Build">
        <MSBuild Projects="TfsBuildTestTarget.sln" Targets="TfsBuildTestTarget" Properties="Configuration=Release;Platform=Win32"/>
    </Target>
</Project>

When I run MSBUILD on this project file, I get the following error:

"c:\dev\TfsBuildTestTarget\testBuild.proj" (default target) (1 ) -> "c:\dev\TfsBuildTestTarget\TfsBuildTestTarget.sln" (TfsBuildTe stTarget target) (2) -> (TfsBuildTestTarget target) ->
c:\dev\TfsBuildTestTarget\TfsBuildTestTarget\TfsBuildTestTarget.vcxproj(3,14): error MSB4066: The attribute "Label" in element is unrecognized.

The referenced line, in the (VS-generated) vcxproj file looks like this:

  <ItemGroup Label="ProjectConfigurations">

The reference for the MSBuild item element does not include a Label attribute.

What is going on here? Why is VS2010 generating project files that do not appear to be compatible with MSBuild? Is there a way for me to build this solution as part of an MSBuild project without manually tweaking the XML?

like image 603
Eric Avatar asked Feb 24 '11 16:02

Eric


2 Answers

Make sure you are using the .NET 4.0 version of MSBuild.

If you use the .NET 3.5 version of MSBuild against a VS2010 solution that includes a vcxproj file you will get this error.

I made a c++ console application like you specified and ran it using both .NET 3.5 and .NET 4.0 MSBuild versions. I got the error using 3.5 and it worked using 4.0.

The Label attribute is new in .NET 4.0. It can be added to ItemGroup, PropertyGroup, Target, and other elements. The label attribute is not mentioned in the online help for msbuild but is defined int he msbuild 4.0 schema files.

like image 121
Brian Walker Avatar answered Sep 21 '22 22:09

Brian Walker


I was using the "Open Visual Studio Command Prompt (2008)" entry of Start Menu to build, and it gave me the same error, but when I switched to "Open Visual Studio Command Prompt (2010)", I had the problem miracolously solved.

like image 44
sergiol Avatar answered Sep 21 '22 22:09

sergiol