bazelbuild / rules_dotnet

.NET rules for Bazel
Apache License 2.0
184 stars 79 forks source link

Transitive analyzers cause conflicts when strict deps are disabled #443

Open sin-ack opened 2 weeks ago

sin-ack commented 2 weeks ago

There is a simplistic check to elide assemblies when they are already present, but the same isn't done for analyzers: https://github.com/bazelbuild/rules_dotnet/blob/626e28effb14f87de8375186ebb59911a16b71fb/dotnet/private/common.bzl#L315

I ended up having the following compile flags passed down:

/analyzer:external/_main~main_extension~nuget.microsoft.extensions.configuration.binder.v8.0.1/analyzers/dotnet/cs/Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll
...
/analyzer:external/rules_dotnet~~targeting_packs_extension~nuget.microsoft.aspnetcore.app.ref.v8.0.3/analyzers/dotnet/cs/Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll

Which gives me the following compile error:

Microsoft.Extensions.Configuration.Binder.SourceGeneration/Microsoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator/BindingExtensions.g.cs(40,10): error CS0433: The type 'InterceptsLocationAttribute' exists in both 'Server, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Server, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
Microsoft.Extensions.Configuration.Binder.SourceGeneration/Microsoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator/BindingExtensions.g.cs(40,10): error CS0433: The type 'InterceptsLocationAttribute' exists in both 'Server, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Server, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

Should the same transitive check be added for analyzers?

purkhusid commented 2 weeks ago

Any chance that you could create a small repro of this? Also, does this work with strict deps enabled?

sin-ack commented 1 week ago

Sorry for not responding. I'll try to create a repro in the weekend. Yes, this works fine with strict deps as analyzers aren't transitively included then. I'd be interested in figuring out if there's a well-defined assembly resolution algorithm so that we can have a general way of solving this.