|
13 | 13 | AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets" |
14 | 14 | DependsOnTargets="MVVMToolkitGatherAnalyzers"> |
15 | 15 |
|
16 | | - <!-- Use the CSharpCoreTargetsPath property to find the version of the compiler we are using. This is the same mechanism |
17 | | - MSBuild uses to find the compiler. We could check the assembly version for any compiler assembly (since they all have |
18 | | - the same version) but Microsoft.Build.Tasks.CodeAnalysis.dll is where MSBuild loads the compiler tasks from so if |
19 | | - someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check. --> |
| 16 | + <!-- |
| 17 | + Use the CSharpCoreTargetsPath property to find the version of the compiler we are using. This is the same mechanism |
| 18 | + MSBuild uses to find the compiler. We could check the assembly version for any compiler assembly (since they all have |
| 19 | + the same version) but Microsoft.Build.Tasks.CodeAnalysis.dll is where MSBuild loads the compiler tasks from so if |
| 20 | + someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check. |
| 21 | + --> |
20 | 22 | <GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine(`$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))"> |
21 | 23 | <Output TaskParameter="Assemblies" ItemName="MVVMToolkitCurrentCompilerAssemblyIdentity"/> |
22 | 24 | </GetAssemblyIdentity> |
23 | 25 |
|
24 | 26 | <PropertyGroup> |
25 | | - |
26 | 27 | <!-- Transform the resulting item from GetAssemblyIdentity into a property representing its assembly version --> |
27 | 28 | <MVVMToolkitCurrentCompilerVersion>@(MVVMToolkitCurrentCompilerAssemblyIdentity->'%(Version)')</MVVMToolkitCurrentCompilerVersion> |
28 | 29 |
|
|
35 | 36 | <Analyzer Remove="@(MVVMToolkitAnalyzer)"/> |
36 | 37 | </ItemGroup> |
37 | 38 |
|
38 | | - <!-- If the source generators are disabled, also emit a warning. This would've been produced by MSBuild itself as well, but |
39 | | - emitting this manually lets us customize the message to inform developers as to why exactly the generators have been |
40 | | - disabled, and that the rest of the MVVM Toolkit will still keep working as intended, just without additional features. --> |
| 39 | + <!-- |
| 40 | + If the source generators are disabled, also emit a warning. This would've been produced by MSBuild itself as well, but |
| 41 | + emitting this manually lets us customize the message to inform developers as to why exactly the generators have been |
| 42 | + disabled, and that the rest of the MVVM Toolkit will still keep working as intended, just without additional features. |
| 43 | + --> |
41 | 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."/> |
42 | 45 | </Target> |
43 | 46 |
|
44 | 47 | <!-- |
45 | | - Manually remove duplicate analyzers if Roslyn component versioning is not supported (ie. if a legacy .csproj project is used). |
46 | | - This target is only run if Roslyn 4.0 or greater is present, as otherwise all analyzers would have already been removed anyway. |
| 48 | + Manually remove duplicate analyzers if Roslyn component versioning is not supported (ie. if a legacy .csproj project is used). |
| 49 | + This target is only run if Roslyn 4.0 or greater is present, as otherwise all analyzers would have already been removed anyway. |
47 | 50 | --> |
48 | 51 | <Target Name="MVVMToolkitRemoveDuplicateAnalyzersWhenRoslynComponentVersioningIsNotSupported" |
49 | 52 | Condition="'$(MVVMToolkitCurrentCompilerVersionIsNotNewEnough)' != 'true' AND '$(SupportsRoslynComponentVersioning)' != 'true'" |
50 | 53 | AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets" |
51 | 54 | DependsOnTargets="MVVMToolkitRemoveAnalyzersForRoslyn3"> |
52 | 55 |
|
53 | | - <!-- |
| 56 | + <!-- |
54 | 57 | This switch manually implements Roslyn component versioning. That is, it checks the current version of Roslyn and |
55 | 58 | removes and removes all analyzers except the highest version that is supported. The fallback is just Roslyn 4.0. |
56 | | - --> |
| 59 | + --> |
57 | 60 | <PropertyGroup> |
58 | 61 | <MVVMToolkitSelectedRoslynAnalyzerDirectoryName Condition="$([MSBuild]::VersionGreaterThanOrEquals($(MVVMToolkitCurrentCompilerVersion), 4.3))">roslyn4.3</MVVMToolkitSelectedRoslynAnalyzerDirectoryName> |
59 | 62 | <MVVMToolkitSelectedRoslynAnalyzerDirectoryName Condition="'$(MVVMToolkitSelectedRoslynAnalyzerDirectoryName)' == ''">roslyn4.0</MVVMToolkitSelectedRoslynAnalyzerDirectoryName> |
60 | 63 | </PropertyGroup> |
61 | | - <ItemGroup> |
62 | | - |
63 | | - <!-- |
| 64 | + |
| 65 | + <!-- |
64 | 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. |
65 | 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 |
66 | 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 |
67 | 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 |
68 | 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. |
69 | | - --> |
| 71 | + --> |
| 72 | + <ItemGroup> |
70 | 73 | <Analyzer Remove="@(MVVMToolkitAnalyzer)" Condition="!$([System.String]::Concat('', '%(MVVMToolkitAnalyzer.FullPath)').Contains('$(MVVMToolkitSelectedRoslynAnalyzerDirectoryName)'))"/> |
71 | 74 | </ItemGroup> |
72 | 75 | </Target> |
|
0 commit comments