Skip to content

Commit

Permalink
Don't use Roslyn toolset package for APICompat validation on desktop …
Browse files Browse the repository at this point in the history
…msbuild < 17.9.0

Contributes (works around) #32691

When using a desktop msbuild / VS < 17.9.0 and using an out-of-band Roslyn >= 4.9.0, APICompat fails to load dependencies like SCI and epically fails.

This adds a workaround to not use the out-of-band Roslyn for APICompat.
  • Loading branch information
ViktorHofer authored and github-actions committed Feb 6, 2024
1 parent 9bf036d commit a5b1698
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project>

<!-- Expose the tasks for SDK consumption and for external use cases. -->
<UsingTask TaskName="Microsoft.DotNet.ApiCompat.Task.ValidateAssembliesTask" AssemblyFile="$(DotNetApiCompatTaskAssembly)" />
<UsingTask TaskName="Microsoft.DotNet.ApiCompat.Task.ValidatePackageTask" AssemblyFile="$(DotNetApiCompatTaskAssembly)" />

<Target Name="CollectApiCompatInputs">
<PropertyGroup Condition="'$(RoslynAssembliesPath)' == ''">
<RoslynAssembliesPath>$(RoslynTargetsPath)</RoslynAssembliesPath>
<_packageReferenceList>@(PackageReference)</_packageReferenceList>

<_UsesRoslynToolsetPackage Condition="'@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.Net.Compilers.Toolset'))' == 'true'">true</_UsesRoslynToolsetPackage>
<!-- CSharpCoreTargetsPath and VisualBasicCoreTargetsPath point to the same location, Microsoft.CodeAnalysis.CSharp and Microsoft.CodeAnalysis.VisualBasic
are on the same directory as Microsoft.CodeAnalysis. So there is no need to distinguish between csproj or vbproj. -->
<RoslynAssembliesPath Condition="$(_packageReferenceList.Contains('Microsoft.Net.Compilers.Toolset'))">$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))</RoslynAssembliesPath>
<RoslynAssembliesPath Condition="'$(_UsesRoslynToolsetPackage)' == 'true'">$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))</RoslynAssembliesPath>
<RoslynAssembliesPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$([System.IO.Path]::Combine('$(RoslynAssembliesPath)', bincore))</RoslynAssembliesPath>

<!-- Temporary workaround to mitigate https://github.com/dotnet/sdk/issues/32691 with roslyn toolset package and desktop msbuild < 17.9.0.
Reset the roslyn assemblies path back to Roslyn inside Visual Studio. -->
<RoslynAssembliesPath Condition="'$(MSBuildRuntimeType)' != 'Core' and '$(_UsesRoslynToolsetPackage)' == 'true' and '$(MSBuildVersion)' &lt; '17.9.0'">$(RoslynTargetsPath)</RoslynAssembliesPath>
</PropertyGroup>

<!-- Respect legacy property and item names. -->
Expand All @@ -47,4 +53,5 @@ Copyright (c) .NET Foundation. All rights reserved.
Condition="Exists($(_apiCompatDefaultProjectSuppressionFile))" />
</ItemGroup>
</Target>

</Project>

0 comments on commit a5b1698

Please sign in to comment.