From 1027e5372ff2f0d16b7fe177f1eae72bffc034e3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 14 Feb 2020 08:34:23 -0800 Subject: [PATCH] Use the analyzer from the SDK when available (#18885) * Use the analyzer from the SDK when available This prevents a build warning when building a project that contains a reference to Microsoft.AspNetCore.Components and a netcoreapp3.0 or newer targeting Web project. The Web SDK implicitly adds the Components.Analyzer for netcoreapp3.0 or newer targeting projects. If the project additionally referenced this package (directly or transitively), the package would set up a property that prevented the implicit analyzer reference. This prevented the analyzer from being referenced twice. There were two issues with the current approach: a) The props file wasn't propogated via buildTransitive. Consequently transitive project references would reference two copies of the analyzer. When these were different versions, it resulted in a compiler warning. b) Forward looking, this prevents newer versions of the analyzer shipped from the SDK from ever being used. This is particularly problematic since apps are likely to reference component libraries that were previously compiled against 3.x. This change attempts to mitigate both of these issues: a) We add a buildTransitive so our build targets flow b) We knock out the analyzer added by the package if the SDK's already added it. Fixes https://github.com/dotnet/aspnetcore/issues/18563 * Update Microsoft.AspNetCore.Components.Analyzers.targets * Update Microsoft.AspNetCore.Components.Analyzers.targets * Add a description * Update Microsoft.AspNetCore.Components.Analyzers.targets --- ...oft.AspNetCore.Components.Analyzers.csproj | 1 + ...soft.AspNetCore.Components.Analyzers.props | 5 --- ...ft.AspNetCore.Components.Analyzers.targets | 34 +++++++++++++++++++ ...ft.AspNetCore.Components.Analyzers.targets | 3 ++ 4 files changed, 38 insertions(+), 5 deletions(-) delete mode 100644 src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.props create mode 100644 src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets create mode 100644 src/Components/Analyzers/src/buildTransitive/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets diff --git a/src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj b/src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj index a83904f245..903de47c78 100644 --- a/src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj +++ b/src/Components/Analyzers/src/Microsoft.AspNetCore.Components.Analyzers.csproj @@ -18,6 +18,7 @@ + diff --git a/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.props b/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.props deleted file mode 100644 index 0ba7b4da05..0000000000 --- a/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.props +++ /dev/null @@ -1,5 +0,0 @@ - - - true - - diff --git a/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets b/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets new file mode 100644 index 0000000000..d8c68fd5ee --- /dev/null +++ b/src/Components/Analyzers/src/build/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets @@ -0,0 +1,34 @@ + + + + + <_AspNetCoreComponentsAnalyzerName Include="$([System.IO.Path]::GetFileNameWithoutExtension('%(Analyzer.Identity)'))" /> + + + + <_AspNetCoreComponentsAnalyzerPath>$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)../../analyzers/dotnet/cs/Microsoft.AspNetCore.Components.Analyzers.dll')) + + + + + + + diff --git a/src/Components/Analyzers/src/buildTransitive/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets b/src/Components/Analyzers/src/buildTransitive/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets new file mode 100644 index 0000000000..fd79fdac66 --- /dev/null +++ b/src/Components/Analyzers/src/buildTransitive/netstandard2.0/Microsoft.AspNetCore.Components.Analyzers.targets @@ -0,0 +1,3 @@ + + +