54 行
3.0 KiB
XML
54 行
3.0 KiB
XML
<Project>
|
|
|
|
<!-- Get the analyzer from the ComputeSharp.Core NuGet package -->
|
|
<Target Name="_ComputeSharpCoreGatherAnalyzers">
|
|
<ItemGroup>
|
|
<_ComputeSharpCoreAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'ComputeSharp.Core'" />
|
|
</ItemGroup>
|
|
</Target>
|
|
|
|
<!-- Remove the analyzer if using Roslyn < 4.2 (ComputeSharp.Core's generators require Roslyn 4.2) -->
|
|
<Target Name="_ComputeSharpCoreRemoveAnalyzersForRoslyn3"
|
|
Condition="'$(CSharpCoreTargetsPath)' != ''"
|
|
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
|
|
DependsOnTargets="_ComputeSharpCoreGatherAnalyzers">
|
|
|
|
<!-- Use the CSharpCoreTargetsPath property to find the version of the compiler we are using. This is the same mechanism
|
|
MSBuild uses to find the compiler. We could check the assembly version for any compiler assembly (since they all have
|
|
the same version) but Microsoft.Build.Tasks.CodeAnalysis.dll is where MSBuild loads the compiler tasks from so if
|
|
someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check. -->
|
|
<GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine(`$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))">
|
|
<Output TaskParameter="Assemblies" ItemName="ComputeSharpCoreCurrentCompilerAssemblyIdentity"/>
|
|
</GetAssemblyIdentity>
|
|
|
|
<PropertyGroup>
|
|
|
|
<!-- Transform the resulting item from GetAssemblyIdentity into a property representing its assembly version -->
|
|
<ComputeSharpCoreCurrentCompilerVersion>@(ComputeSharpCoreCurrentCompilerAssemblyIdentity->'%(Version)')</ComputeSharpCoreCurrentCompilerVersion>
|
|
|
|
<!-- The CurrentCompilerVersionIsNotNewEnough property can now be defined based on the Roslyn assembly version -->
|
|
<ComputeSharpCoreCurrentCompilerVersionIsNotNewEnough Condition="$([MSBuild]::VersionLessThan($(ComputeSharpCoreCurrentCompilerVersion), 4.2))">true</ComputeSharpCoreCurrentCompilerVersionIsNotNewEnough>
|
|
</PropertyGroup>
|
|
|
|
<!-- If the Roslyn version is < 4.2, disable the source generators -->
|
|
<ItemGroup Condition ="'$(ComputeSharpCoreCurrentCompilerVersionIsNotNewEnough)' == 'true'">
|
|
<Analyzer Remove="@(_ComputeSharpCoreAnalyzer)"/>
|
|
</ItemGroup>
|
|
|
|
<!-- There is no need to emit a warning here, as this package is always a transitive dependency from ComputeSharp, which does emit the warning -->
|
|
</Target>
|
|
|
|
<!-- Remove the analyzer if Roslyn is missing -->
|
|
<Target Name="_ComputeSharpCoreRemoveAnalyzersForRosynNotFound"
|
|
Condition="'$(CSharpCoreTargetsPath)' == ''"
|
|
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
|
|
DependsOnTargets="_ComputeSharpCoreGatherAnalyzers">
|
|
|
|
<!-- If no Roslyn assembly could be found, just remove the analyzer without emitting a warning -->
|
|
<ItemGroup>
|
|
<Analyzer Remove="@(_ComputeSharpCoreAnalyzer)"/>
|
|
</ItemGroup>
|
|
</Target>
|
|
|
|
</Project>
|