tunnelvisionlabs / antlr4cs

The original, highly-optimized C# Target for ANTLR 4
Other
444 stars 104 forks source link

Azure Pipelines Build/VisualStudio DesignTime magic #338

Open cpyfferoen opened 4 years ago

cpyfferoen commented 4 years ago

There are a host of issues logged that discuss dotnet core etc. specifically #208 but...

Please help guide me? csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.0;netstandard2.1</TargetFrameworks>
    <NeutralLanguage>en-US</NeutralLanguage>
    <LangVersion>7.3</LangVersion>
    <Version>1.1.0-dev</Version>
    <Antlr4UseCSharpGenerator>true</Antlr4UseCSharpGenerator>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Antlr4" Version="4.6.6" />
    <PackageReference Include="StringTemplate4" Version="4.0.9-rc1" />
  </ItemGroup>
  <ItemGroup>
    <Antlr4 Update="NeutralTextParser\NTLexer.g4">
      <CustomToolNamespace>MagicNamespace</CustomToolNamespace>
      <Listener>False</Listener>
      <Visitor>False</Visitor>
    </Antlr4>
  </ItemGroup>
</Project>

azure yaml

- task: MSBuild@1
  continueOnError: true
  displayName: 'Try MSBuild'
  inputs:
    solution: '$(project)'
    platform: $(buildPlatform)
    configuration: $(buildConfiguration)

- task: DotNetCoreCLI@2
  displayName: 'Just for fun, see if msbuild made the files..'
  inputs:
    command: 'build'
    projects: $(project)
cpyfferoen commented 4 years ago

Update - perhaps it has something to do with a fragments file - I do have an import MagicFragments; line in two Lexers, but I did not have a build task for the fragments - trying this now.. Yeah.. I can't get any dotnet build or dotnet msbuild working w/ an import MagicFragments in it. It magically works as soon as I open VisualStudio, it creates the *.tokens files.. but seems like black magic since it doesn't work outside of VisualStudio

cpyfferoen commented 4 years ago

No combination of <Abstract/> <Antlr4AbstractGrammar/> or a host of other settings will produce, using the dotnet CLI (dotnet build or dotnet msbuild), tokens for any grammar that has an Imports in it. Possibly this is related to #111 - but as soon as I start visual studio (don't even build or click any buttons) bamm! It generates the *.tokens file for my partials, and everything works there after..

cpyfferoen commented 4 years ago

Workaround (aka cheating):

- task: DotNetCoreCLI@2
  displayName: 'dotnet msbuild $(project)'
  continueOnError: true
  inputs:
    command: 'custom'
    projects: '$(project)'
    custom: 'msbuild'
    arguments: '/p:DesignTimeBuild=true /p:Configuration=$(buildConfiguration)'
# yes, the above task fails.. so build again!!!
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '$(project)'
    arguments: '-c $(buildConfiguration)'

and the powershell to achieve same result

dotnet restore
dotnet msbuild /p:DesignTimeBuild=true
dotnet build
sharwell commented 4 years ago

Can you create a minimal project to reproduce this, and submit it as a pull request to https://github.com/tunnelvisionlabs/antlr-integration-tests-csharp? I expect the pull request to initially fail, at which point I can work to find a solution to it.