开发者

Configure the message compiler (mc.exe) as a custom compiler step in VC++ 2010?

Can anyone list the specific and d开发者_JAVA百科etailed steps to configure mc.exe (the message compiler) to compile a .mc file into a .rc file as a custom compiler step in VC++ 2010?

I am really lost on how to do this.


Hans Passant almost had it right. Unfortunately, $(InputPath) and $(InputName) aren't defined in VS 2010. Instead, create your message file:

  • Right click on your project->Add->New Item
  • Select "Text File (.txt), but name it as a ".mc" file (like "messages.mc")
  • Create a resource file (say, "resources.rc")
  • Edit the resources file so it contains only one line:

#include "messages.rc"

That file will be generated by the message compiler. Now add a custom build step to run the message compiler:

  • Right-click on messages.mc and select Properties.
  • In the Properties dialog set Configuration to "All Configurations".
  • Under "Configuration Properties" click on "General".
  • Ensure the "Excluded From Build" property is set to "No".
  • Set the "Item Type" property to "Custom Build Tool" from the drop-down menu and click the "Apply" button so the "Custom Build Tool" property will appear.
  • Click on "General" under the "Custom Build Tool" property.
  • Set the "Command Line" property to:

    mc %(FullPath)

  • Set the Description property to something like "Compiling Messages..."

  • Set Outputs property to:

    %(Filename).rc;%(Filename).h;MSG0409.bin

The file MSG00409.bin is from having the following line in messages.mc:

LanguageNames = (English=0x409:MSG00409)

There can be a bin file for each language you add to messages.mc. The nice part of listing them in the output is that it will be deleted when the project is cleaned.

The only thing I'm not sure about is setting the "Execute Before" property to guarantee messages.rc is generated before resource.rc is compiled. I didn't have to set it, but if you find the resource compiler is trying to execute before the message compiler, then you'll have to set this property. It's disabled for the "messages.mc" file, but it can be set in the project's "Custom Build Step" property.


Right-click the project, Add + New Item, select Text File, name it Blah.mc. Enter or paste the definitions. Right-click Blah.mc, Properties, Custom build step:

  • Command line = mc $(InputPath)
  • Outputs = $(InputName).rc

Edit your .rc file, add:

#include "Blah.rc"

Worked for me, ought to be close.


If you want to use a Custom Build Rule, you can do this

  • Right click your project in Visual Studio -> Custom Build Rules
  • Click "New Rule File" and fill out the fields, I use this rule file for MC.EXE

    <VisualStudioToolFile Name="Message Table Build Rule" Version="8.00">
      <Rules>
        <CustomBuildRule
          Name="Message Table Build Rule"
          DisplayName="Message Table Build Rule"
          CommandLine="[Location]\mc.exe [Unicode] [Verbose] [Inputs]"
          Outputs="Message Table Build Rule"
          FileExtensions="*.mc"
          ExecutionDescription="Message Table Build Rule"
           >
          <Properties>
            <BooleanProperty
              Name="Verbose"
              DisplayName="Verbose mode"
              Description="Foo."
              Switch="-v"
            />
            <BooleanProperty
              Name="Unicode"
              DisplayName="Unicode mode"
              Description="Bar."
              Switch="-u"
            />
            <StringProperty
              Name="Location"
              DisplayName="Location"
              Description="Baz."
              Switch="[value]"
              DefaultValue="C:\Bin\Psdk\Bin"
            />
          </Properties>
        </CustomBuildRule>
      </Rules>
    </VisualStudioToolFile>
    


In case custom compiler is not a requirement but more how to make it build .rc files from MSBuild. The WDK MessageCompiler task offers this integration with MSBuild

  <ItemGroup>
    <MessageCompile Include="a.mc">
      <GenerateBaselineResource>true</GenerateBaselineResource>
      <BaselineResourcePath>c:\test\</BaselineResourcePath>
    </MessageCompile>
  </ItemGroup>


In Visual Studio 2017 - then you can do following:

open up the .vcxproj file for your project, then add following lines inside the ItemDefinitionGroup :

<CustomBuildStep>
  <Command>mc "$(InputDir)\$(InputName).mc" -r "$(InputDir)\res" -h "$(InputDir)"</Command>
</CustomBuildStep>

This should generate 3 files .h, .rc, and .res - look in the designated build folder

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜