Google cloud build C# source generator, 'Could not load file or assembly Microsoft.CodeAnalysis'

Viewed 128

I have been trying to use an C# source generator during the Google Cloud Build but i keep getting an error:

Step #1 - "build": CSC : warning CS8032: An instance of analyzer generator/sourceGenerator cannot be created from /layers/google.dotnet.publish/packages/generator/2.0.0/analyzers/dotnet/cs/generator.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.. [/workspace/generator-app/generator-app.csproj]

Part of the application csproj that uses the generator:

<PropertyGroup>      
  <TargetFramework>netcoreapp3.1</TargetFramework>     
  <ImplicitUsings>enable</ImplicitUsings>     
  <Nullable>enable</Nullable>     
  <LangVersion>8.0</LangVersion>   
</PropertyGroup>

The source generator csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" />
  </ItemGroup>
</Project>

I have tried to downgrade the Microsoft.CodeAnalysis.CSharp and Microsoft.CodeAnalysis.Analyzers packages but that does not work.

Google cloud build uses SDK Version: 3.1.416

0 Answers
Related