MSBuild似乎仅将旧的输出文件用于自定义生成工具 [英] MSBuild appears to only use old output files for custom build tools

查看:68
本文介绍了MSBuild似乎仅将旧的输出文件用于自定义生成工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ANTLR语法文件作为C#项目文件的一部分,并按照用户手册.

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>

无论出于何种原因,Compile步骤仅使用旧版本的代码,而似乎没有任何调节作用.

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

按旧版本",我的意思是,如果我清洗解决方案,构建项目,则Foo.g将生成FooLexer.csFooParser.cs.然后,如果我对Foo.g进行更新并重新编译,则将忽略lexer和解析器C#文件的新版本,并使用旧版本.我必须再次编译...

By "old versions," I mean that if I clean the solution, build the project, Foo.g will make FooLexer.cs and FooParser.cs. Should I then make an update to Foo.g and recompile, the new versions of the lexer and parser C# files are ignored and the old versions are used. I have to compile a second time...

推荐答案

IDE中似乎存在一个错误:Visual Studio仅监视它自己修改的C#文件中的更改(例如,设计师生成的代码).对于在IDE外部修改/生成的代码(例如ANTLR之类的外部工具),它将使用文件的内存版本,而无需从磁盘刷新文件.

There seems to be a bug in the IDE: Visual Studio only monitors changes in C# files that it modifies itself (e.g. designer generated code). For code modified/generated outside of the IDE (e.g. external tool like ANTLR) it will use the in-memory version of the file, without refreshing it from the disk.

解决方法是不使用托管"缓存,而是生成外部CSC进程来编译项目.您可以通过将"UseHostCompilerIfAvailable"项目属性设置为false来实现此目的,就像在.csproj中一样:

The workaround is to not use the "hosted" cache, and instead spawn an external CSC process to compile the project. You do this by setting the "UseHostCompilerIfAvailable" project property to false like so in your .csproj:

<UseHostCompilerIfAvailable>FALSE</UseHostCompilerIfAvailable>

有关更多信息,请参见

For more info, see this entry in the MS Connect website.

我在Visual Studio中遇到了与ANTLR完全相同的问题,这为我解决了这个问题.但是,有些人在将该选项设置为"false"后报告了项目间依赖关系的问题,因此请注意副作用...

I had the exact same problem as you with ANTLR in Visual Studio, and this fixed it for me. However, some people report problems with project-to-project dependencies after setting that option to 'false' so watch out for side effects...

这篇关于MSBuild似乎仅将旧的输出文件用于自定义生成工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆