GitInfo icon indicating copy to clipboard operation
GitInfo copied to clipboard

Non-deterministic compile errors on ThisAssembly.GitInfo.g.cs

Open Davidvanluijk opened this issue 4 years ago • 2 comments

I recently started using the gitinfo nuget package, but on the build server I randomly get build errors: ...\obj\x86\Release\ThisAssembly.GitInfo.g.cs(38,35): error CS1525: Invalid expression term '' [project.csproj] ...\obj\x86\Release\ThisAssembly.GitInfo.g.cs(38,35): error CS1056: Unexpected character '$' [project.csproj] ...\obj\x86\Release\ThisAssembly.GitInfo.g.cs(38,36): error CS1002: ; expected [project.csproj] ...\obj\x86\Release\ThisAssembly.GitInfo.g.cs(38,46): error CS1519: Invalid token '$' in class, record, struct, or interface member declaration [project.csproj] ...\obj\x86\Release\ThisAssembly.GitInfo.g.cs(38,46): error CS1056: Unexpected character '$' [project.csproj]

Restarting the build fixes it and I haven't seen it on my local machine yet. Moreover: the file seems just fine if I open it later on.

I use gitinfo by adding it to Directory.Build.props:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	...
  <ItemGroup>
    <PackageReference Include="GitInfo" Version="2.1.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
  <Target Name="SetVersion" AfterTargets="GitVersion" BeforeTargets="GetPackageVersion;GitThisAssembly" Condition="'$(ExcludeRestorePackageImports)' != 'true'">
    <PropertyGroup>
      <Version>$(SemanticVersion)</Version>
	  <Dirty Condition='$(GitIsDirty)==1'>*</Dirty>
	  <Dirty Condition='$(GitIsDirty)!=1'/>
      <InformationalVersion>$(SemanticVersion).$(GitCommit)$(Dirty)-$(Configuration)-$(COMPUTERNAME)</InformationalVersion>
    </PropertyGroup>
  </Target>
</Project>

Is there something what I should do differently?

Davidvanluijk avatar Jul 30 '21 07:07 Davidvanluijk

Hard to say without a clean repro. Perhaps you could attach a binlog?

kzu avatar Aug 26 '21 05:08 kzu

I took some time to capture the situation, because most of the time the next build was already running before I detected the issue occured. Attached is the log file (I did remove some info there), I have the repo as well if required.

The offending file is CIU-DEV0-JOB1%!%company%!%.Common.Installer.Utilities\obj\Release\ThisAssembly.GitInfo.g.cs (attached as txt CSBuild.log ) ThisAssembly.GitInfo.g.cs.txt

Davidvanluijk avatar Nov 05 '21 09:11 Davidvanluijk

Sorry the long time in replying. This seems to be some unreplaced $GitIsDirty$ token from way back then. I haven't seen any newer reports and I haven't been able to repro with current builds either. Perhaps you have already moved on from GitInfo, but perhaps not and you can confirm this no longer happens?

Thanks!

PS: plz do reopen if it still happens.

kzu avatar Feb 06 '23 22:02 kzu