Skip to content

Commit eff7168

Browse files
authored
Merge pull request #91 from CommunityToolkit/dev/targets-update
Update .targets for MVVM Toolkit to fix .wapproj issues
2 parents d3d9752 + 9b1596d commit eff7168

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.targets

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<!-- Remove the analyzer if using Roslyn 3.x (incremental generators require Roslyn 4.x) -->
1111
<Target Name="_MVVMToolkitRemoveAnalyzersForRoslyn3"
12+
Condition="'$(CSharpCoreTargetsPath)' != ''"
1213
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
1314
DependsOnTargets="_MVVMToolkitGatherAnalyzers">
1415

@@ -19,26 +20,37 @@
1920
<GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine(`$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))">
2021
<Output TaskParameter="Assemblies" ItemName="CurrentCompilerAssemblyIdentity"/>
2122
</GetAssemblyIdentity>
22-
23+
2324
<PropertyGroup>
2425

2526
<!-- Transform the resulting item from GetAssemblyIdentity into a property representing its assembly version -->
2627
<CurrentCompilerVersion>@(CurrentCompilerAssemblyIdentity->'%(Version)')</CurrentCompilerVersion>
27-
28+
2829
<!-- The CurrentCompilerVersionIsNotNewEnough property can now be defined based on the Roslyn assembly version -->
2930
<CurrentCompilerVersionIsNotNewEnough Condition="$([MSBuild]::VersionLessThan($(CurrentCompilerVersion), 4.0))">true</CurrentCompilerVersionIsNotNewEnough>
30-
<CurrentCompilerVersionIsNotNewEnough Condition="$(CurrentCompilerVersionIsNotNewEnough) == ''">false</CurrentCompilerVersionIsNotNewEnough>
3131
</PropertyGroup>
32-
32+
3333
<!-- If the Roslyn version is < 4.0, disable the source generators -->
34-
<ItemGroup Condition ="$(CurrentCompilerVersionIsNotNewEnough) == 'true'">
34+
<ItemGroup Condition ="'$(CurrentCompilerVersionIsNotNewEnough)' == 'true'">
3535
<Analyzer Remove="@(_MVVMToolkitAnalyzer)"/>
3636
</ItemGroup>
37-
37+
3838
<!-- If the source generators are disabled, also emit a warning. This would've been produced by MSBuild itself as well, but
3939
emitting this manually lets us customize the message to inform developers as to why exactly the generators have been
4040
disabled, and that the rest of the MVVM Toolkit will still keep working as intended, just without additional features. -->
41-
<Warning Condition ="$(CurrentCompilerVersionIsNotNewEnough) == '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."/>
41+
<Warning Condition ="'$(CurrentCompilerVersionIsNotNewEnough)' == '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+
</Target>
43+
44+
<!-- Remove the analyzer if Roslyn is missing -->
45+
<Target Name="_MVVMToolkitRemoveAnalyzersForRosynNotFound"
46+
Condition="'$(CSharpCoreTargetsPath)' == ''"
47+
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
48+
DependsOnTargets="_MVVMToolkitGatherAnalyzers">
49+
50+
<!-- If no Roslyn assembly could be found, just remove the analyzer without emitting a warning -->
51+
<ItemGroup>
52+
<Analyzer Remove="@(_MVVMToolkitAnalyzer)"/>
53+
</ItemGroup>
4254
</Target>
4355

4456
</Project>

0 commit comments

Comments
 (0)