10 April 2007

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. 



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'.


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


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


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: ,


Anonymous said...

It would be nice to get rid of these warnings though. Perhaps it is the retentive nature in me, but I take pride in code that compiles without warning of any kind, even the kind you 'can ignore'.

Steven St Jean said...

I agree. I hate having to explain to clients that "this really isn't a problem". Like you said, if the compiler gives me a warning then I expect that it is valid.

On the other hand, the nature of MSBuild is such that you would be hard pressed to describe it in a schema. That's the beauty and flexibility of it.

So all-in-all, I'll keep letting my clients know that they can ignore it and let the teams at Microsoft keep cranking out new goodness for me to play with. :)

- Steve

Sergio Rykov said...

Hello, Steve. I see you've faced difficulties with extending msbuild process. But it was year ago. In our current project we want to minimize a set of general properties which should be injected in each proj file like *.csproj (e.g. CodeAnalysisDictionary, SignAssembly, AssemblyOriginatorKeyfile and so on). May be now you know MS-provided method to eliminate warnings when project is loading in VS or some kind of hack?

Steven St Jean said...

Hi Sergio,

I think I understand you, if not then let me know.

The .csproj file is a simple MSBuild file. If you have a common set of properties to add to it you can always create a custom MSBuild file with those properties and then just Import that file into the .csproj file.

Anonymous said...

If i ran VS2008 as an administrator on Vista i don't get my error anymore. Thanks for the post and descriptive title

Anonymous said...

It's still trashy to leave error messages that clearly call out issues. It might be nice to have a list of "known" OK warnings to reference.

Anonymous said...

I am having same error coz of that project is not getting loaded

Khanh said...

Thanks so much. I thought I made some mistakes in my code.

Anonymous said...

I am having the same problem while trying to build a RIA Services project. The error states:

The element 'PropertyGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element 'RiaClientCodeGenDependsOn' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'.

Any idea?

Steven St Jean said...

If this is a Warning and not an Error then you are fine and are seeing the issue that I describe. The project files are just MSBuild files.

It sounds like you or one of your tools has added a PropertyGroup to your project file to create a Name-Value pair.

Post a Comment