diff options
author | Viktor Hofer <viktor.hofer@microsoft.com> | 2022-05-12 10:22:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 10:22:26 +0300 |
commit | d3af4921f36dba8dde35ade7dff59a3a192edddb (patch) | |
tree | cdaf3acef9a30cdb90fada81bed2ede820e4fc0c /eng | |
parent | 35e47797a36e29475d28af61f0fa0fb3bf067838 (diff) |
Define convention to consume and/or package analyzers (#69069)
* Define convention to include analyzers in ref pack
Fixes https://github.com/dotnet/runtime/issues/61321
Until now we required source libraries to define ProjectReferences when
an analyzer should be part of the shared framework. That strategy causes
analyzer projects to leak into the ProjectReference closure and by that
into a solution file.
As an example:
When another library references the source library that references the
analyzer, the analyzer is part of the dependency closure even though it
might not be required.
This change makes it possible to define the shared framework analyzer
projects in the NetCoreAppLibrary.props file for both the .NETCoreApp,
and the AspNetCoreApp shared framework.
Out-of-band projects which ship analyzers inside their produced package,
continue to reference the analyzers via the `AnalyzerProject` item.
* Use AnalyzerReference consistently
* Don't reference analyzer when its packaged
* Fix P2P reference
* Fix multi target roslyn component target condition
Diffstat (limited to 'eng')
-rw-r--r-- | eng/generators.targets | 17 | ||||
-rw-r--r-- | eng/packaging.targets | 15 |
2 files changed, 18 insertions, 14 deletions
diff --git a/eng/generators.targets b/eng/generators.targets index 69c3c12cbb4..c123ad66387 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -41,17 +41,18 @@ That is required as the EnabledGenerators condition checks on the Reference and ProjectReference items and hence can't be a property condition. --> <ItemGroup Condition="'@(EnabledGenerators)' != '' and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'LibraryImportGenerator'))"> - <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\LibraryImportGenerator\LibraryImportGenerator.csproj; - $(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" - OutputItemType="Analyzer" - ReferenceOutputAssembly="false" /> + <AnalyzerReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\LibraryImportGenerator\LibraryImportGenerator.csproj; + $(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj" /> </ItemGroup> - <!-- Use a normal property condition as this source generator is opt-in and doesn't read from an item list. --> - <ItemGroup Condition="'$(EnableRegexGenerator)' == 'true'"> - <ProjectReference Include="$(LibrariesProjectRoot)System.Text.RegularExpressions\gen\System.Text.RegularExpressions.Generator.csproj" + <!-- AnalyzerReference items are transformed to ProjectReferences with the required analyzer metadata. --> + <ItemGroup> + <ProjectReference Include="@(AnalyzerReference)" + ReferenceOutputAssembly="false" OutputItemType="Analyzer" - ReferenceOutputAssembly="false" /> + Pack="false" /> + <ProjectReference Update="@(AnalyzerReference->WithMetadataValue('ReferenceAnalyzer', 'false'))" + OutputItemType="" /> </ItemGroup> <Target Name="ConfigureGenerators" diff --git a/eng/packaging.targets b/eng/packaging.targets index 1abe280c590..91d72a574c7 100644 --- a/eng/packaging.targets +++ b/eng/packaging.targets @@ -137,11 +137,12 @@ </ItemGroup> </Target> - <Target Name="IncludeAnalyzersInPackage" Condition="'@(AnalyzerReference)' != ''"> - <!-- Call a target in the analyzer project to get all the files it would normally place in a package. - These will be returned as items with identity pointing to the built file, and PackagePath metadata - set to their location in the package. IsSymbol metadata will be set to distinguish symbols. --> - <MSBuild Projects="@(AnalyzerReference)" + <!-- Call a target in the analyzer project to get all the files it would normally place in a package. + These will be returned as items with identity pointing to the built file, and PackagePath metadata + set to their location in the package. IsSymbol metadata will be set to distinguish symbols. --> + <Target Name="IncludeAnalyzersInPackage" + Condition="'@(AnalyzerReference)' != '' and @(AnalyzerReference->AnyHaveMetadataValue('Pack', 'true'))"> + <MSBuild Projects="@(AnalyzerReference->WithMetadataValue('Pack', 'true'))" Targets="GetAnalyzerPackFiles"> <Output TaskParameter="TargetOutputs" ItemName="_AnalyzerFile" /> </MSBuild> @@ -165,7 +166,9 @@ <!-- In packages that contain Analyzers, include a .targets file that will select the correct analyzer. --> <Target Name="IncludeMultiTargetRoslynComponentTargetsInPackage" AfterTargets="IncludeAnalyzersInPackage" - Condition="'@(AnalyzerReference)' != '' and '$(IncludeMultiTargetRoslynComponentTargets)' == 'true'" + Condition="'@(AnalyzerReference)' != '' and + @(AnalyzerReference->AnyHaveMetadataValue('Pack', 'true')) and + '$(IncludeMultiTargetRoslynComponentTargets)' == 'true'" DependsOnTargets="GenerateMultiTargetRoslynComponentTargetsFile"> <ItemGroup> <Content Include="$(MultiTargetRoslynComponentTargetsFileIntermediatePath)" PackagePath="buildTransitive\netstandard2.0\$(PackageId).targets" /> |