|
1 | 1 | <Project>
|
2 | 2 |
|
3 | 3 | <!-- Get the analyzer from the CommunityToolkit.Mvvm NuGet package -->
|
4 |
| - <Target Name="MVVMToolkitGatherAnalyzers"> |
| 4 | + <Target Name="MVVMToolkit_GatherAnalyzers"> |
5 | 5 | <ItemGroup>
|
6 |
| - <MVVMToolkitAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'CommunityToolkit.Mvvm'" /> |
| 6 | + <MVVMToolkit_Analyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'CommunityToolkit.Mvvm'" /> |
7 | 7 | </ItemGroup>
|
8 | 8 | </Target>
|
9 | 9 |
|
10 | 10 | <!-- Remove the analyzer if using Roslyn 3.x (incremental generators require Roslyn 4.x) -->
|
11 |
| - <Target Name="MVVMToolkitRemoveAnalyzersForRoslyn3" |
| 11 | + <Target Name="MVVMToolkit_RemoveAnalyzers_WhenRoslynVersionIsNotSupported" |
12 | 12 | Condition="'$(CSharpCoreTargetsPath)' != ''"
|
13 | 13 | AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
|
14 |
| - DependsOnTargets="MVVMToolkitGatherAnalyzers"> |
| 14 | + DependsOnTargets="MVVMToolkit_GatherAnalyzers"> |
15 | 15 |
|
16 | 16 | <!--
|
17 | 17 | Use the CSharpCoreTargetsPath property to find the version of the compiler we are using. This is the same mechanism
|
18 | 18 | MSBuild uses to find the compiler. We could check the assembly version for any compiler assembly (since they all have
|
19 | 19 | the same version) but Microsoft.Build.Tasks.CodeAnalysis.dll is where MSBuild loads the compiler tasks from so if
|
20 | 20 | someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check.
|
21 | 21 | -->
|
22 |
| - <GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine(`$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))"> |
23 |
| - <Output TaskParameter="Assemblies" ItemName="MVVMToolkitCurrentCompilerAssemblyIdentity"/> |
| 22 | + <GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine($([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath))), 'Microsoft.Build.Tasks.CodeAnalysis.dll'))"> |
| 23 | + <Output TaskParameter="Assemblies" ItemName="MVVMToolkit_CurrentCompilerAssemblyIdentity"/> |
24 | 24 | </GetAssemblyIdentity>
|
25 | 25 |
|
26 | 26 | <PropertyGroup>
|
27 | 27 | <!-- Transform the resulting item from GetAssemblyIdentity into a property representing its assembly version -->
|
28 |
| - <MVVMToolkitCurrentCompilerVersion>@(MVVMToolkitCurrentCompilerAssemblyIdentity->'%(Version)')</MVVMToolkitCurrentCompilerVersion> |
| 28 | + <MVVMToolkit_CurrentCompilerVersion>@(MVVMToolkit_CurrentCompilerAssemblyIdentity->%(Version))</MVVMToolkit_CurrentCompilerVersion> |
29 | 29 |
|
30 |
| - <!-- The CurrentCompilerVersionIsNotNewEnough property can now be defined based on the Roslyn assembly version --> |
31 |
| - <MVVMToolkitCurrentCompilerVersionIsNotNewEnough Condition="$([MSBuild]::VersionLessThan($(MVVMToolkitCurrentCompilerVersion), 4.0))">true</MVVMToolkitCurrentCompilerVersionIsNotNewEnough> |
| 30 | + <!-- The CurrentCompilerIsNotNewEnough property can now be defined based on the Roslyn assembly version --> |
| 31 | + <MVVMToolkit_CurrentCompilerIsNotNewEnough Condition="$([MSBuild]::VersionLessThan($(MVVMToolkit_CurrentCompilerVersion), 4.0))">true</MVVMToolkit_CurrentCompilerIsNotNewEnough> |
32 | 32 | </PropertyGroup>
|
33 | 33 |
|
34 | 34 | <!-- If the Roslyn version is < 4.0, disable the source generators -->
|
35 |
| - <ItemGroup Condition ="'$(MVVMToolkitCurrentCompilerVersionIsNotNewEnough)' == 'true'"> |
36 |
| - <Analyzer Remove="@(MVVMToolkitAnalyzer)"/> |
| 35 | + <ItemGroup Condition ="'$(MVVMToolkit_CurrentCompilerIsNotNewEnough)' == 'true'"> |
| 36 | + <Analyzer Remove="@(MVVMToolkit_Analyzer)"/> |
37 | 37 | </ItemGroup>
|
38 | 38 |
|
39 | 39 | <!--
|
40 | 40 | If the source generators are disabled, also emit a warning. This would've been produced by MSBuild itself as well, but
|
41 | 41 | emitting this manually lets us customize the message to inform developers as to why exactly the generators have been
|
42 | 42 | disabled, and that the rest of the MVVM Toolkit will still keep working as intended, just without additional features.
|
43 | 43 | -->
|
44 |
| - <Warning Condition ="'$(MVVMToolkitCurrentCompilerVersionIsNotNewEnough)' == 'true'" Text="The MVVM Toolkit source generators have been disabled on the current configuration, as they need Roslyn 4.x in order to work. The MVVM Toolkit will work just fine, but features relying on the source generators will not be available."/> |
| 44 | + <Warning Condition ="'$(MVVMToolkit_CurrentCompilerIsNotNewEnough)' == 'true'" Text="The MVVM Toolkit source generators have been disabled on the current configuration, as they need Roslyn 4.x in order to work. The MVVM Toolkit will work just fine, but features relying on the source generators will not be available."/> |
45 | 45 | </Target>
|
46 | 46 |
|
47 | 47 | <!--
|
48 |
| - Manually remove duplicate analyzers if Roslyn component versioning is not supported (ie. if a legacy .csproj project is used). |
| 48 | + Manually remove additional analyzers if Roslyn component versioning is not supported (ie. if a legacy .csproj project is used). |
49 | 49 | This target is only run if Roslyn 4.0 or greater is present, as otherwise all analyzers would have already been removed anyway.
|
50 | 50 | -->
|
51 |
| - <Target Name="MVVMToolkitRemoveDuplicateAnalyzersWhenRoslynComponentVersioningIsNotSupported" |
52 |
| - Condition="'$(MVVMToolkitCurrentCompilerVersionIsNotNewEnough)' != 'true' AND '$(SupportsRoslynComponentVersioning)' != 'true'" |
| 51 | + <Target Name="MVVMToolkit_RemoveAdditionalAnalyzers_WhenRoslynComponentVersioningIsNotSupported" |
| 52 | + Condition="'$(MVVMToolkit_CurrentCompilerIsNotNewEnough)' != 'true' AND '$(SupportsRoslynComponentVersioning)' != 'true'" |
53 | 53 | AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
|
54 |
| - DependsOnTargets="MVVMToolkitRemoveAnalyzersForRoslyn3"> |
| 54 | + DependsOnTargets="MVVMToolkit_RemoveAnalyzers_WhenRoslynVersionIsNotSupported"> |
55 | 55 |
|
56 | 56 | <!--
|
57 | 57 | This switch manually implements Roslyn component versioning. That is, it checks the current version of Roslyn and
|
58 | 58 | removes and removes all analyzers except the highest version that is supported. The fallback is just Roslyn 4.0.
|
59 | 59 | -->
|
60 | 60 | <PropertyGroup>
|
61 |
| - <MVVMToolkitSelectedRoslynAnalyzerDirectoryName Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MVVMToolkitCurrentCompilerVersion), 4.3))">roslyn4.3</MVVMToolkitSelectedRoslynAnalyzerDirectoryName> |
62 |
| - <MVVMToolkitSelectedRoslynAnalyzerDirectoryName Condition="'$(MVVMToolkitSelectedRoslynAnalyzerDirectoryName)' == ''">roslyn4.0</MVVMToolkitSelectedRoslynAnalyzerDirectoryName> |
| 61 | + <MVVMToolkit_SelectedRoslynAnalyzerTarget Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MVVMToolkit_CurrentCompilerVersion), 4.3))">roslyn4.3</MVVMToolkit_SelectedRoslynAnalyzerTarget> |
| 62 | + <MVVMToolkit_SelectedRoslynAnalyzerTarget Condition="'$(MVVMToolkit_SelectedRoslynAnalyzerTarget)' == ''">roslyn4.0</MVVMToolkit_SelectedRoslynAnalyzerTarget> |
63 | 63 | </PropertyGroup>
|
64 | 64 |
|
65 | 65 | <!--
|
66 | 66 | This condition is a bit convoluted, but it's essentially just selecting all analyzers from the NuGet package that don't have the target Roslyn directory name in their full path.
|
67 | 67 | For instance, if Roslyn 4.3 is the highest supported version, the target directory name will be "roslyn 4.3", and this condition will filter out all analyzers with a path such
|
68 |
| - as: "C:\...\.nuget\...\CommunityToolkit.Mvvm\analyzers\roslyn4.0\cs\CommunityToolkit.Mvvm". The [System.String]::Concat trick is used to achieve two things: we can't directly |
| 68 | + as: "C:\...\.nuget\...\CommunityToolkit.Mvvm\analyzers\roslyn4.0\cs\CommunityToolkit.Mvvm". The [System.String]::Copy trick is used to achieve two things: we can't directly |
69 | 69 | invoke a property function (ie. Contains in this case) on a metadata item, so we need an intermediate string to invoke it on. We could also use [System.String]::new, but using
|
70 |
| - Concat is more efficient as it'll just skip the allocation entirely if one of the two inputs is an empty string, which is the case here. |
| 70 | + Copy is more efficient (on .NET Framework runtime) as it'll just skip the allocation entirely. |
71 | 71 | -->
|
72 | 72 | <ItemGroup>
|
73 |
| - <Analyzer Remove="@(MVVMToolkitAnalyzer)" Condition="!$([System.String]::Concat('', '%(MVVMToolkitAnalyzer.FullPath)').Contains('$(MVVMToolkitSelectedRoslynAnalyzerDirectoryName)'))"/> |
| 73 | + <Analyzer Remove="@(MVVMToolkit_Analyzer)" Condition="!$([System.String]::Copy(%(MVVMToolkit_Analyzer.FullPath)).Contains($(MVVMToolkit_SelectedRoslynAnalyzerTarget)))"/> |
74 | 74 | </ItemGroup>
|
75 | 75 | </Target>
|
76 | 76 |
|
77 | 77 | <!-- Remove the analyzer if Roslyn is missing -->
|
78 |
| - <Target Name="MVVMToolkitRemoveAnalyzersForRosynNotFound" |
| 78 | + <Target Name="MVVMToolkit_RemoveAnalyzers_WhenRoslynIsNotFound" |
79 | 79 | Condition="'$(CSharpCoreTargetsPath)' == ''"
|
80 | 80 | AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
|
81 |
| - DependsOnTargets="MVVMToolkitGatherAnalyzers"> |
| 81 | + DependsOnTargets="MVVMToolkit_GatherAnalyzers"> |
82 | 82 |
|
83 | 83 | <!-- If no Roslyn assembly could be found, just remove the analyzer without emitting a warning -->
|
84 | 84 | <ItemGroup>
|
85 |
| - <Analyzer Remove="@(MVVMToolkitAnalyzer)"/> |
| 85 | + <Analyzer Remove="@(MVVMToolkit_Analyzer)"/> |
86 | 86 | </ItemGroup>
|
87 | 87 | </Target>
|
88 | 88 |
|
|
0 commit comments