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/packaging.targets | |
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/packaging.targets')
-rw-r--r-- | eng/packaging.targets | 15 |
1 files changed, 9 insertions, 6 deletions
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" /> |