简体   繁体   中英

MSBuild element 'ItemGroup' in Namespace on VS2013 generated *.vcxproj file


I'm heading up the newbie learning curve on using MSBuild. I am working on some custom build vxproj files and Intellisense is reporting what appear to be "false" errors. I get "element 'ItemGroup' in namespace 'schema' has invalid child element. This link suggests that the issue is with the MSDEV checker.

To make a "simple" example, I used VS2013 to create a "dummy" MFCLibrary1 vxcproj file and edit that to see if this problem occurs with a valid project. It does. It finds an invalid child element at the ItemGroup where the Readme.txt is an Include item. (its in the screen shot but possibly hard to see). I also highlighted that block of code in bold. This is similar to the errors I get when I look at other projects, or add what seem to be valid items to a working project. It's difficult to determine if I'm violating the schema as I'm still learning the schema.

错误的屏幕截图

The code generated by VS2013 is below. This was generated using the Project Wizard, then just opened as a file as a example of the problem I see. This valid project file is throwing Intellisense warnings.
What I want to do is to figure a way to inform Intellisense of the proper Schema so that I can get error checking as I make simple modifications to customize a working project. As a newbie, I want all the tools/assistance I can get to have the system help me learn how to do customization properly. Starting out by ignoring Intellisense means I might as well use any other editor.

The solution seems to be using an XML editor that can be force fed all the schema. I'm just not up on ?xsd? enough to know if there is a way to add tokens to the projecct below so that I can use VS2013 to edit the file intelligently with Intellisense support.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{F68857AB-780A-4373-BDD7-2CFCFE30270E}</ProjectGuid>
    <RootNamespace>MFCLibrary1</RootNamespace>
    <Keyword>MFCDLLProj</Keyword>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v120</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
    <UseOfMfc>Dynamic</UseOfMfc>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <ModuleDefinitionFile>.\MFCLibrary1.def</ModuleDefinitionFile>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0409</Culture>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>Use</PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <ModuleDefinitionFile>.\MFCLibrary1.def</ModuleDefinitionFile>
    </Link>
    <Midl>
      <MkTypLibCompatible>false</MkTypLibCompatible>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ResourceCompile>
      <Culture>0x0409</Culture>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ResourceCompile>
  </ItemDefinitionGroup>
  **<ItemGroup>
    <Text Include="ReadMe.txt" />
  </ItemGroup>**
  <ItemGroup>
    <ClCompile Include="MFCLibrary1.cpp" />
    <ClCompile Include="stdafx.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="MFCLibrary1.h" />
    <ClInclude Include="Resource.h" />
    <ClInclude Include="stdafx.h" />
    <ClInclude Include="targetver.h" />
  </ItemGroup>
  <ItemGroup>
    <None Include="MFCLibrary1.def" />
    <None Include="res\MFCLibrary1.rc2" />
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="MFCLibrary1.rc" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

figure a way to inform Intellisense of the proper Schema

Thing is, there is no 'proper' schema because of the custom tasks, properties and items which can be added at will. So one way to deal with this, even as a beginner, is what many of us do: ignore all warnings and only look at the errors as the latter will actually cause the project to fail loading whereas the former usually don't.

That being said, the xsd files used for validation of msbuild xml files are under

C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Xml\\Schemas\\1033\\

and the files are

MSBuild\\Microsoft.Build.Commontypes.xsd and MsBuild\\Microsoft.Build.Core.xsd and Microsoft.Build.xsd

so if you really want to spend time on this, go berserk and add names of all properties you do not want to see warnings for in that last file, it even mentions

<!-- ========= ADD CUSTOM ITEMS, PROPERTIES, AND TASKS BELOW ======= -->

with some examples. For more examples, scroll to about line 995 of that Commontypes.xsd where it lists a bunch of known properties. Anything you add you won't get a warning for anymore. I don't have any experience with xsd files so maybe it's possible to use some kind of wildcard instead. But in any case you'd be messing with the VS install and obiously other pc's you might work on lack those modifications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM