Antlr には、生成されたコードをプロジェクトに追加するために使用できるプロセスの例があります。これには、ソース ファイルの下にネストされて生成されたファイルを表示できるという利点がありますが、追加するのはより複雑です。
生成元のファイルを含む項目グループを追加する必要があります。次に例を示します。
<ItemGroup>
  <ServiceDescription Include="MyService.txt"/>
</ItemGroup>
次に、生成される cs ファイルを、残りのソース コードを含む ItemGroup に追加します。
<ItemGroup>
  ...
  <Compile Include="Program.cs" />
  <Compile Include="Properties\AssemblyInfo.cs" />
  ...etc..
  <Compile Include="MyService.txt.cs">
    <AutoGen>True</AutoGen>
    <DesignTime>True</DesignTime>
    <DependentUpon>MyService.txt</DependentUpon>  <!--note: this should be the file name of the source file, not the path-->      
  </Compile>
</ItemGroup>      
そして最後にビルド ターゲットを追加してコード生成を実行します (% を使用して、ItemGroup 内の各項目に対してコマンドを実行します)。これは別のファイルに入れることができるので、多くのプロジェクトから含めることができます。
<Target Name="GenerateService">
  <Exec Command="servicegen.exe -i:%(ServiceDescription.Identity) -o:%(ServiceDescription.Identity).cs" />
</Target>
<PropertyGroup>
  <BuildDependsOn>GenerateService;$(BuildDependsOn)</BuildDependsOn>
</PropertyGroup>