Skip to content

Commit faf1061

Browse files
committed
Add workaround for Roslyn 4.3 issues
1 parent 65110da commit faf1061

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

CommunityToolkit.Mvvm.SourceGenerators/CommunityToolkit.Mvvm.SourceGenerators.props

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
<MvvmToolkitSourceGeneratorRoslynPatchVersion>$(MSBuildProjectName.Substring($([MSBuild]::Subtract($(MSBuildProjectName.Length), 1)), 1))</MvvmToolkitSourceGeneratorRoslynPatchVersion>
2828
<MvvmToolkitSourceGeneratorRoslynVersion>$(MvvmToolkitSourceGeneratorRoslynMajorVersion).$(MvvmToolkitSourceGeneratorRoslynMinorVersion).$(MvvmToolkitSourceGeneratorRoslynPatchVersion)</MvvmToolkitSourceGeneratorRoslynVersion>
2929

30-
<!-- Also define a "ROSLYN_<MAJOR>_<MINOR>" build constant, so the generator code can multi-target whenever needed and add any required polyfills -->
31-
<DefineConstants>$(DefineConstants);ROSLYN_$(MvvmToolkitSourceGeneratorRoslynVersion.Substring(0, 3).Replace('.', '_'))</DefineConstants>
30+
<!-- Workaround for https://github.com/dotnet/roslyn/issues/63919 -->
31+
<MvvmToolkitSourceGeneratorRoslynVersion Condition="'$(MvvmToolkitSourceGeneratorRoslynVersion)' == '4.3.0'">4.4.0-1.final</MvvmToolkitSourceGeneratorRoslynVersion>
32+
33+
<!-- Also define "ROSLYN_<MAJOR>_<MINOR>_OR_GREATER" build constants, so the generator code can multi-target whenever needed and add any required polyfills -->
34+
<DefineConstants Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MvvmToolkitSourceGeneratorRoslynVersion), 4.3))">$(DefineConstants);ROSLYN_4_3_0_OR_GREATER</DefineConstants>
3235
</PropertyGroup>
3336

3437
<ItemGroup>

CommunityToolkit.Mvvm.SourceGenerators/Extensions/ISymbolExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Immutable;
6-
#if !ROSLYN_4_3
6+
#if !ROSLYN_4_3_0_OR_GREATER
77
using System.Diagnostics.CodeAnalysis;
88
#endif
99
using Microsoft.CodeAnalysis;
@@ -67,7 +67,7 @@ public static bool HasAttributeWithFullyQualifiedName(this ISymbol symbol, strin
6767
return false;
6868
}
6969

70-
#if !ROSLYN_4_3
70+
#if !ROSLYN_4_3_0_OR_GREATER
7171
/// <summary>
7272
/// Tries to get an attribute with the specified full name.
7373
/// </summary>

CommunityToolkit.Mvvm.SourceGenerators/Polyfills/GeneratorAttributeSyntaxContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if !ROSLYN_4_3
5+
#if !ROSLYN_4_3_0_OR_GREATER
66

77
using System.Collections.Immutable;
88

CommunityToolkit.Mvvm.SourceGenerators/Polyfills/SyntaxValueProviderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if !ROSLYN_4_3
5+
#if !ROSLYN_4_3_0_OR_GREATER
66

77
using System.Threading;
88
using System;

CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@
5757
<!--
5858
Pack the source generator to the right package folders (each matching the target Roslyn version).
5959
Roslyn will automatically load the highest version compatible with Roslyn's version in the SDK.
60+
The Roslyn 4.3 target is copied to the 4.4 folder as a workaround for https://github.com/dotnet/roslyn/issues/63919.
6061
-->
6162
<None Include="..\CommunityToolkit.Mvvm.SourceGenerators.Roslyn401\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Mvvm.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn4.0\cs" Pack="true" Visible="false" />
62-
<None Include="..\CommunityToolkit.Mvvm.SourceGenerators.Roslyn430\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Mvvm.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn4.3\cs" Pack="true" Visible="false" />
63+
<None Include="..\CommunityToolkit.Mvvm.SourceGenerators.Roslyn430\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Mvvm.SourceGenerators.dll" PackagePath="analyzers\dotnet\roslyn4.4\cs" Pack="true" Visible="false" />
6364
</ItemGroup>
6465

6566
</Project>

tests/CommunityToolkit.Mvvm.SourceGenerators.Roslyn430.UnitTests/CommunityToolkit.Mvvm.SourceGenerators.Roslyn430.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest" Version="1.1.1" />
9-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0" />
9+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0-1.final" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
1111
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
1212
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />

0 commit comments

Comments
 (0)