Visual Studio Warning: The element ‘xxxx’ in namespace ‘http://schemas.microsoft.com/developer/msbuild/2003’ has invalid child element ‘yyyy’ in namespace ‘http://schemas.microsoft.com/developer/msbuild/2003’.

How’s that for a descriptive title…  I wanted to make sure the search engines could find this posting. 🙂

During a recent foray into the MSBuild Forums on MSDN, I came across a post from a developer that was asking why he was seeing the above warning on a valid property declaration in his csproj file. 

 

Problem:

When editing MSBuild project files (vbproj, csproj, targets, etc.) in the Visual Studio IDE you see a warning on the first property in a PropertyGroup or the first item in an ItemGroup stating:

Warning  The element ‘xxxx’ in namespace ‘http://schemas.microsoft.com/developer/msbuild/2003’ has invalid child element ‘yyyy’ in namespace ‘http://schemas.microsoft.com/developer/msbuild/2003’. List of possible elements expected: ‘Property’ in namespace ‘http://schemas.microsoft.com/developer/msbuild/2003’.

Issue:

When you apply the schema attribute to your Project element, Visual Studio reads in the schema and uses the information indide to provide Intellisense during your editing.  As an offshoot of this, it also warns you when it finds that you have used elements or attributes that are not part of the schema.  The custom property and item elements are not part of the MSBuild schema.


Click thumbnail for full-sized image

Discussion:

The designers of MSBuild created a base schema that outlined the fundamental constructs of the MSBuild project file format.  They designed the system to be open ended so that we would be able to add our own elements to the file outside of those defined in the schema.  This is how we get the ability to set custom properties and item groups as well as being able to use custom tasks.  If the MSBuild system wasn’t so flexible, the designers would have had to build the schema with every conceivable property and item group name or run the risk of constraining the use of the tool.


Click thumbnail for full-sized image

Solution:

You can safely ignore this warning.  So does MSBuild validate your project files against the schema?  Yes it does, but I wasn’t sure just how it was accomplished, so I fired off an email to Buck Hodges.  He was nice enough to pass it by an as-yet-unnamed-dev on the MSBuild team.  The dev stated that

…MSBuild does try to validate against the schema.  However, the validation is done at runtime by our code rather than loading the [project] file using a validate reader with the xsd (mainly for perf reasons).  MSBuild should fail any projects which don’t adhere to the schema.

So there you have it.  The schema is enforced while still allowing you to customize and extend the MSBuild project file to fit your needs.

Something else to note…

Only the first property or item in the groups gets marked by the IDE as not conforming to the schema.  You will also see the same behavior arise if you use a custom task in your targets.

 

 

Technorati tags: ,