【问题标题】:generated files from ANTLR conflict in visual studio between release and debug modesVisual Studio 中发布和调试模式之间的 ANTLR 冲突生成的文件
【发布时间】:2017-04-17 01:37:22
【问题描述】:

我将ANTLR4Visual StudioC# 一起使用。在构建过程中,ANTLR4 工具会生成 6 个C# 源文件(即 Parser、Lexer、Visitor、Listener 等),它们对应于 ANTLR 生成的解析器。该文件在项目的 obj/Debug 目录中生成(假设选择了 Debug 模式)。我将这些文件作为链接添加到解决方案资源管理器中以检查生成的代码。

如果我尝试更改为发布模式ANTLR4 在项目的 obj/Release 目录中生成相同的文件,并且这些文件与在 obj/Debug 目录中生成的文件发生冲突(同一命名空间中的重复类)。

问题是:

当我处于发布模式并完成上述操作时,有没有办法将解决方案资源管理器中生成的文件从调试模式中排除(在发布模式下),或者我必须从解决方案中手动排除 obj/Debug 目录explorer 以避免冲突?

提前致谢

【问题讨论】:

    标签: visual-studio build antlr


    【解决方案1】:

    我为同样的问题苦苦挣扎。主要问题,已将文件链接到项目调试配置。因此,当您切换到 RELEASE 配置时,链接仍然存在,现在您的项目中有重复的定义。 obj/DEBUG 路径中的可见和 obj/RELEASE 路径中的不可见

    我不知道在 VS-GUI 上解决此问题的任何解决方案。但是可以修补 cproj 文件以获得可接受的解决方案:

    首先是原始部分:

    ...
    <ItemGroup>
        <Compile Include="DataRepository.cs" />
        <Compile Include="SpreadsheetErrorListener.cs" />
        <Compile Include="SpreadsheetVisitor.cs" />
        <Compile Include="Program.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
        <Compile Include="obj\Debug\SpreadsheetBaseListener.cs" />
        <Compile Include="obj\Debug\SpreadsheetBaseVisitor.cs" />
        <Compile Include="obj\Debug\SpreadsheetLexer.cs" />
        <Compile Include="obj\Debug\SpreadsheetListener.cs" />
        <Compile Include="obj\Debug\SpreadsheetParser.cs" />
        <Compile Include="obj\Debug\SpreadsheetVisitor.cs" />
    </ItemGroup>
    ...
    

    你的应该看起来很相似。

    我将 ItemGroups 拆分为:

    ...
    <ItemGroup>
        <Compile Include="DataRepository.cs" />
        <Compile Include="SpreadsheetErrorListener.cs" />
        <Compile Include="SpreadsheetVisitor.cs" />
        <Compile Include="Program.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
    </ItemGroup>
    <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <Compile Include="obj\Release\SpreadsheetBaseListener.cs" />
        <Compile Include="obj\Release\SpreadsheetBaseVisitor.cs" />
        <Compile Include="obj\Release\SpreadsheetLexer.cs" />
        <Compile Include="obj\Release\SpreadsheetListener.cs" />
        <Compile Include="obj\Release\SpreadsheetParser.cs" />
        <Compile Include="obj\Release\SpreadsheetVisitor.cs" />
    </ItemGroup>
    <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <Compile Include="obj\Debug\SpreadsheetBaseListener.cs" />
        <Compile Include="obj\Debug\SpreadsheetBaseVisitor.cs" />
        <Compile Include="obj\Debug\SpreadsheetLexer.cs" />
        <Compile Include="obj\Debug\SpreadsheetListener.cs" />
        <Compile Include="obj\Debug\SpreadsheetParser.cs" />
        <Compile Include="obj\Debug\SpreadsheetVisitor.cs" />
    </ItemGroup>
    ...
    

    在 VS 中,两个目录都是可见的,但只有一个用于 Intellisense 和编译期间。

    当前选择的文件显示为“openers”(抱歉不知道正确的名称)

    DEBUG configuration

    RELEASE configuration

    看起来不太好,但解决了问题。

    缺点:

    每次添加新配置时,都必须再次修补 cproj 文件。但这样做是值得的,因为 Intellisense、Resharper 和所有其他不错的小助手都可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-08
      • 2011-09-02
      • 2019-03-22
      • 2013-01-28
      相关资源
      最近更新 更多