MSBuild appears to only use old output files for custom build tools

Posted by sixlettervariables on Stack Overflow See other posts from Stack Overflow or by sixlettervariables
Published on 2010-04-05T16:48:11Z Indexed on 2010/04/05 16:53 UTC
Read the original article Hit count: 411

Filed under:

I have an ANTLR grammar file as part of a C# project file and followed the steps outlined in the User Manual.

<Project ...>
    <PropertyGroup>
        <Antlr3ToolPath>$(ProjectDir)tools\antlr-3.1.3\lib</Antlr3ToolPath>
        <AntlrCleanupPath>$(ProjectDir)AntlrCleanup\$(OutputPath)</AntlrCleanupPath>
    </PropertyGroup>
    <ItemGroup>
        <Antlr3 Include="Grammar\Foo.g">
            <OutputFiles>FooLexer.cs;FooParser.cs</OutputFiles>
        </Antlr3>
        <Antlr3 Include="Grammar\Bar.g">
            <OutputFiles>BarLexer.cs;BarParser.cs</OutputFiles>
        </Antlr3>
    </ItemGroup>
    <Target Name="GenerateAntlrCode"
            Inputs="@(Antlr3)"
            Outputs="%(Antlr3.OutputFiles)">
        <Exec Command="java -cp %22$(Antlr3ToolPath)\antlr-3.1.3.jar%22 org.antlr.Tool -message-format vs2005 @(Antlr3Input)" Outputs="%(Antlr3Input.OutputFiles)" />
        <Exec Command="%22$(AntlrCleanupPath)\AntlrCleanup.exe%22 @(Antlr3Input) %(Antlr3Input.OutputFiles)" />
    </Target>
    <ItemGroup>
         <!-- ...other files here... -->
         <Compile Include="Grammar\FooLexer.cs">
             <AutoGen>True</AutoGen>
             <DesignTime>True</DesignTime>
             <DependentUpon>Foo.g</DependentUpon>
          </Compile>
          <Compile Include="Grammar\FooParser.cs">
              <AutoGen>True</AutoGen>
              <DesignTime>True</DesignTime>
              <DependentUpon>Foo.g</DependentUpon>
          </Compile>
          <!-- ... -->
    </ItemGroup>
</Project>

For whatever reason, the Compile steps only use old versions of the code, no amount of tweaking appears to help.

© Stack Overflow or respective owner

Related posts about msbuild