-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include a .targets file in NuGet packages which will select the corre…
…ct analyzer assembly depending on which Roslyn version will be used to compile.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<Project> | ||
<!-- Reads the version of the compiler APIs that are currently being used in order to pick the correct Roslyn components. --> | ||
<Target Name="_{TargetPrefix}ResolveRoslynApiMajorVersion" | ||
Condition="'$(_RoslynApiMajorVersion)' == ''"> | ||
<GetAssemblyIdentity AssemblyFiles="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll"> | ||
<Output TaskParameter="Assemblies" ItemName="_CodeAnalysisIdentity" /> | ||
</GetAssemblyIdentity> | ||
|
||
<PropertyGroup> | ||
<_RoslynApiMajorVersion>$([System.Version]::Parse(%(_CodeAnalysisIdentity.Version)).Major)</_RoslynApiMajorVersion> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
<Target Name="_{TargetPrefix}RoslynComponentMultiTargeting" | ||
Condition="'$(SupportsRoslynComponentVersioning)' != 'true'" | ||
AfterTargets="ResolveAssemblyReferences" | ||
DependsOnTargets="_{TargetPrefix}ResolveRoslynApiMajorVersion"> | ||
<ItemGroup> | ||
<!-- clear _CurrentAnalyzer, in case some other target is using it. --> | ||
<_CurrentAnalyzer Remove="@(_CurrentAnalyzer)" /> | ||
<_CurrentAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == '{NuGetPackageId}'" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="$([System.Int32]::Parse($(_RoslynApiMajorVersion))) < 4"> | ||
<!-- Remove our analyzers targeting roslyn4.x --> | ||
<Analyzer Remove="@(_CurrentAnalyzer)" | ||
Condition="$([System.String]::Copy('%(_CurrentAnalyzer.Identity)').IndexOf('roslyn4')) >= 0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="$([System.Int32]::Parse($(_RoslynApiMajorVersion))) >= 4"> | ||
<!-- Remove our analyzers targeting roslyn3.x --> | ||
<Analyzer Remove="@(_CurrentAnalyzer)" | ||
Condition="$([System.String]::Copy('%(_CurrentAnalyzer.Identity)').IndexOf('roslyn3')) >= 0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$({DisableSourceGeneratorPropertyName})' == 'true'"> | ||
<!-- Remove all our analyzers --> | ||
<Analyzer Remove="@(_CurrentAnalyzer)" /> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters