graphql-dotnet/graphql-dotnet

Analyzers package references compiler version higher than the installed SDK

gao-artur opened this issue · 4 comments

I had an issue where installing GraphQL 7.7.1 broke my CI script, with the following error:

The analyzer assembly '/home/runner/.nuget/packages/graphql.analyzers/7.7.1/analyzers/dotnet/cs/GraphQL.Analyzers.dll' references version '4.6.0.0' of the compiler, which is newer than the currently running version '4.3.0.0'.

However, changing actions/setup-dotnet@v1 to v4 solved the problem. (FYI this project uses .NET 6)

Originally posted by @Shane32 in #3824 (comment)

The lowest version I could use without changing any code is 3.4.0. According to this documentation

Version 3.4 includes C# 8.0 (Visual Studio 2019 version 16.4, .NET Core 3.1)

Note that VS 2019 v16.4 is not supported since Oct 21. The only supported VS 2019 version is 16.11, which means compiler version 3.11.0.

Version 3.11 includes C# 9.0 (Visual Studio 2019 version 16.11, .NET 5)

Also, this SO answer says

Keep reference to "Microsoft.CodeAnalysis.CSharp" at 4.0.1 if it's possible. It already includes IIncrementalGenerator.

We don't use source generators yet, but we will need them in future (v8 or v9).

Version 4.0 includes C# 10.0 (Visual Studio 2022 version 17.0, .NET 6)

So, in v7 we can use the 3.11.0, and with the introduction of the code generator, we can upgrade to 4.0.1.

I like that answer. I wish there was a way we could configure the analyzers to skip and not break the build process if there’s an incompatibility.

The alternative is to remove the analyzer dependency from the main project and encourage people to manually install it. But I'd prefer to keep the automatic installation. What do you think?

I strongly suggest we stick with automatic for now.

It is likely possible to use conditional compilation so that only people targeting newer .NET Core versions get the analyzers. I’m fine waiting until someone raises an issue before addressing it though.