代码之家  ›  专栏  ›  技术社区  ›  user7116

msbuild似乎只对自定义生成工具使用旧的输出文件

  •  1
  • user7116  · 技术社区  · 16 年前

    我有一个ANTLR语法文件作为C项目文件的一部分,并遵循 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>
    

    无论出于什么原因, Compile 步骤只使用旧版本的代码,没有多少调整看起来有帮助。

    “旧版本”是指如果我清理解决方案,就构建项目, Foo.g 将使 FooLexer.cs FooParser.cs . 我应该更新一下吗 Fo.g 重新编译时,将忽略lexer和parser c文件的新版本,并使用旧版本。我得再编译一次…

    1 回复  |  直到 16 年前
        1
  •  1
  •   Ludovic Chabant    16 年前

    似乎在IDE中有一个bug:Visual Studio只监视它自己修改的C文件中的更改(例如设计器生成的代码)。对于在IDE之外修改/生成的代码(例如,外部工具如antlr),它将使用文件的内存版本,而不从磁盘刷新。

    解决方法是不使用“托管”缓存,而是生成一个外部CSC进程来编译项目。通过将.csproj中的“useHostCompilerIfAvailable”项目属性设置为false,可以做到这一点:

    <UseHostCompilerIfAvailable>FALSE</UseHostCompilerIfAvailable>

    有关详细信息,请参阅 this entry in the MS Connect website .

    在Visual Studio中,我和您在Antlr上遇到了完全相同的问题,这为我解决了这个问题。但是,有些人在将该选项设置为“false”后会报告项目到项目依赖关系的问题,因此请注意副作用…