dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.36k stars 4.75k forks source link

Determine why analyzers are running on generated not supported assemblies auto-generated files #84104

Open stephentoub opened 1 year ago

stephentoub commented 1 year ago

Our root .editorconfig lists *.notsupported.cs as being consider auto-generated, but for some reason that .editorconfig isn't being passed to csc when building those assemblies, e.g. Microsoft.Win32.Registry. As a result, analyzers are running on the auto-generated .notsupported.cs file there.

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries See info in area-owners.md if you want to be subscribed.

Issue Details
Our root .editorconfig lists *.notsupported.cs as being consider auto-generated, but for some reason that .editorconfig isn't being passed to csc when building those assemblies, e.g. Microsoft.Win32.Registry. As a result, analyzers are running on the auto-generated .notsupported.cs file there.
Author: stephentoub
Assignees: -
Labels: `area-Infrastructure-libraries`
Milestone: -
ViktorHofer commented 1 year ago

Roslyn's msbuild targets auto-discover editorconfig files based on the compile items defined: https://github.com/dotnet/roslyn/blob/3b23723934d3c7d0b3c1a0165def4a7f0e6e3a19/src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets#L125-L140

TFMs that are pure PNSEs don't have any compile items defined at evaluation time. The compile item that is generated by GenFacades which is called NotSupported.cs doesn't exist at evaluation time and hence the logic is skipped.

To fix this for PNSE projects (which are a dotnet/runtime only concept), we could trigger the auto-discovery based on the project file instead. That could be accomplished here: https://github.com/dotnet/arcade/blob/17d9eee32f20a6af0ebb620254a22f601d159578/src/Microsoft.DotNet.GenFacades/build/Microsoft.DotNet.GenFacades.NotSupported.targets#L20

@carlossanlop @ericstj this is another refcount on issues with our PNSE custom infrastructure (in addition to the /// xml comment source of truth issue with PNSEs).

ViktorHofer commented 1 year ago

Filed https://github.com/dotnet/roslyn/issues/67793 as the auto-discovery doesn't work either for projects which define their compile items outside of the project file, in a Directory.Build.targets file. Adding the tracking-external-issue label.

stephentoub commented 1 year ago

Thanks, @ViktorHofer