Custom Build Rule fails after converting to VS2013

553 Views Asked by At

I need to integrate a legacy VS2008 project into my VS2013 solution. This project uses some custom build rules which initially worked after converting the .vcproj to a .vcxproj. However, when doing a fresh checkout of the project including the .vcxproj, the project file can no longer be opened.

I've tracked it down to this issue:

The project file references a couple of custom build rules like this:

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

However, the ms_mc.props file is not present, but there is a ms_mc.rule file. If I convert the VS2008 solution with VS2013 (and assumably also if I opened it in VS2008, which I don't possess), the ms_mc.props file (plus a .targets and a .xml file) is created. However, if I delete that file and open the converted VS2013 project, the file does not get created.

I realized, in the old .vcproj, the corresponding lines are

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

Why does VS2008 reference the .rule file and VS2013 imports the .props file without specifying the .rule file? And more importantly: How can I make this work again?

The .rule and .props file are added for reference


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 (after Conversion to 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>
1

There are 1 best solutions below

0
On BEST ANSWER

I found this blog post for VS2010 which states the following:

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.

and more importantly

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

This basically means that the .XML, .props and .targets files are in fact not created by VS2008; instead, they are a replacement of the old .rules file format since VS2010. Using this information, I can now safely check in those new files without breaking the VS2008 solution. I might have to adapt the new files manually in order to make them work as before, as also mentioned in the blog.