转换为 VS2013 后自定义生成规则失败

Custom Build Rule fails after converting to VS2013

我需要将旧版 VS2008 项目集成到我的 VS2013 解决方案中。该项目使用一些自定义构建规则,这些规则最初在将 .vcproj 转换为 .vcxproj 后起作用。但是,在重新签出包含 .vcxproj 的项目时,无法再打开项目文件。

我已经追踪到这个问题:

项目文件引用了一些自定义构建规则,如下所示:

<ImportGroup Label="ExtensionSettings">
  <Import Project="..\..\..\tools\build\ms_mc.props" />
  (8 similar lines follow)
</ImportGroup>

但是,ms_mc.props 文件不存在,但是存在 ms_mc.rule 文件。如果我用 VS2013 转换 VS2008 解决方案(并且假设我在 VS2008 中打开它,我没有),ms_mc.props 文件(加上一个 .targets 和一个 .xml 文件)是创建。但是,如果我删除该文件并打开转换后的 VS2013 项目,则不会创建该文件。

我意识到,在旧的.vcproj中,对应的行是

<ToolFiles>
  <ToolFile RelativePath="..\..\..\tools\build\ms_mc.rule" />
  (8 similar lines follow)
</ToolFiles>

为什么VS2008引用了.rule文件而VS2013导入了.props文件却没有指定.rule文件?更重要的是:我怎样才能使它再次工作?

添加.rule和.props文件供参考


ms_mc.rule:

<?xml version="1.0" encoding="utf-8"?>
<VisualStudioToolFile
    Name="MS MC"
    Version="8,00"
    >
    <Rules>
        <CustomBuildRule
            Name="MS_MC"
            DisplayName="Microsoft Message Catalogue Compiler"
            CommandLine="mc [Verbose] [inputs] [RCIncludePath] [CIncludePath]"
            Outputs="[$RCIncludePath]$(InputName).rc;[$RCIncludePath]$(InputName).h"
            FileExtensions="*.mc"
            ExecutionDescription="Compiling Message Catalogue $(InputName).mc"
            >
            <Properties>
                <BooleanProperty
                    Name="Verbose"
                    DisplayName="Verbose"
                    Description="Gives verbose output. (-v)"
                    Switch="-v"
                />
                <StringProperty
                    Name="RCIncludePath"
                    DisplayName="RC include file path"
                    Description="Gives the path of where to create the RC include file and the binary message resource files it includes. (-r [pathspec])"
                    Switch="-r [value]"
                    DefaultValue=".\"
                />
                <StringProperty
                    Name="CIncludePath"
                    DisplayName="C include file path"
                    Description="Gives the path of where to create the include header file. (-h [pathspec])"
                    Switch="-h [value]"
                    DefaultValue=".\"
                />
            </Properties>
        </CustomBuildRule>
    </Rules>
</VisualStudioToolFile>

ms_mc.props(转换为 VS2013 后):

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup
    Condition="'$(MS_MCBeforeTargets)' == '' and '$(MS_MCAfterTargets)' == '' and '$(ConfigurationType)' != 'Makefile'">
    <MS_MCBeforeTargets>Midl</MS_MCBeforeTargets>
    <MS_MCAfterTargets>CustomBuild</MS_MCAfterTargets>
  </PropertyGroup>
  <PropertyGroup>
    <MS_MCDependsOn
      Condition="'$(ConfigurationType)' != 'Makefile'">_SelectedFiles;$(MS_MCDependsOn)</MS_MCDependsOn>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <MS_MC>
      <Verbose>False</Verbose>
      <RCIncludePath>.\</RCIncludePath>
      <CIncludePath>.\</CIncludePath>
      <CommandLineTemplate>mc [Verbose] [inputs] [RCIncludePath] [CIncludePath]</CommandLineTemplate>
      <Outputs>%(RCIncludePath)\%(Filename).rc;%(RCIncludePath)\%(Filename).h</Outputs>
      <ExecutionDescription>Compiling Message Catalogue %(Filename).mc</ExecutionDescription>
    </MS_MC>
  </ItemDefinitionGroup>
</Project>

我发现 this blog post 适用于 VS2010,其中说明如下:

Custom build rule is a build feature introduced in VS2005. It provides the ability for the users to easily Plug-In third party tools to use in their build process. The custom build rule is defined by “.rules” files.

更重要的是

In VS2010, due to the migration to MSBuild, the information in the rules file is represented by three files: .XML, .props and .targets files.

这基本上意味着.XML、.props 和.targets 文件实际上不是由VS2008 创建的;相反,它们是自 VS2010 以来旧的 .rules 文件格式的替代品。使用此信息,我现在可以在不破坏 VS2008 解决方案的情况下安全地签入这些新文件。我可能必须手动调整新文件才能使它们像以前一样工作,正如博客中提到的那样。