locked
Missing element according to the MSBuild XML schema?

    Question

  • I am trying to create a new .targets file that I want to share over mulitple projects as described in this blogpost:

    http://blogs.msdn.com/fxcop/archive/2006/11/16/faq-how-do-i-share-managed-code-analysis-rule-settings-over-multiple-projects-david-kean.aspx

     

    Here is how my .targets looks:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>

    <CodeAnalysisRules>-Microsoft.Design#CA2210</CodeAnalysisRules>

    <RunCodeAnalysis>true</RunCodeAnalysis>

    </PropertyGroup>

    </Project>

     

    I get the following warning in Visual Studio 2008:

     

    Warning 1 The element 'Project' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has incomplete content. List of possible elements expected: 'PropertyGroup, ItemGroup, ItemDefinitionGroup, Choose, UsingTask, ProjectExtensions, Target, Import' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'. D:\Projects\ProjectX\CodeAnalysis\TeamA.CodeAnalysis.Rules.targets 6 3 Miscellaneous Files

     

    So what exactly is missing here?


    Wednesday, December 12, 2007 5:14 PM

Answers

  • You can't make the tab read only however if you import your targets file at the bottom of your project, the settings you import from your targets file will override anything you already specified in your project. So while you can't make it read only you can make it so that changing stuff in the tab does nothing.

     

    -Todd

     

    Thursday, December 13, 2007 5:37 PM
    Moderator

All replies

  • You've got the correct format - the warning appears to be a bug in the MSBuild schema - I've filed a bug internally to track this.

     

    Regards

     

    David

     

    Wednesday, December 12, 2007 5:41 PM
    Moderator
  • So as a workaround I could change the XML schema definition?
    Wednesday, December 12, 2007 5:56 PM
  • You could, but I wouldn't advise it due to servicing issues (ie when a future Service Pack is installed). There is no workaround needed as such, MSBuild will happily allow you to import the project from another project without complaining.

    Wednesday, December 12, 2007 6:16 PM
    Moderator
  • So how exactly can I work around this? Should I add specific empty elements to work around this? 

     

    Thursday, December 13, 2007 9:20 AM
  • The workaround is to simply ignore the warning for now. MSBuild should still be able to read your file just fine. Is something actually not working?

     

    Thursday, December 13, 2007 4:52 PM
    Moderator
  • Well at first when I looked in the properties of the project in the code analysis tab the "rules enabled" did not reflect the .targets file and I thought that this was related but after recreating the .targets and changing the project files this appears to be solved. So you are right I could ignore the warning.

     

    Maybe another question and I don't know if I should create a new thread for this but is it possible to make the Code Analysis tab read only?

    Thursday, December 13, 2007 5:24 PM
  • You can't make the tab read only however if you import your targets file at the bottom of your project, the settings you import from your targets file will override anything you already specified in your project. So while you can't make it read only you can make it so that changing stuff in the tab does nothing.

     

    -Todd

     

    Thursday, December 13, 2007 5:37 PM
    Moderator
  • You are right, it really does not matter what the devs select. Well it works like a charm now. The next step is

    programmatically adding the <import> element pointing to the .targets file in our more than 100 projects for a large project. And after that creating a shared Code Analysis Dictionary.

    Thursday, December 13, 2007 5:41 PM