Skip to content

Commit 408c44b

Browse files
committed
Simplify Roslyn assembly resolution logic
1 parent 861beea commit 408c44b

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.targets

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,14 @@
1212
AfterTargets="ResolvePackageDependenciesForBuild;ResolveNuGetPackageAssets"
1313
DependsOnTargets="_MVVMToolkitGatherAnalyzers">
1414

15-
<PropertyGroup>
16-
17-
<!-- If CSharpCoreTargetsPath is not empty, the Roslyn path is the directory name from there -->
18-
<RoslynDirectoryName Condition="$(CSharpCoreTargetsPath) != ''">$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath))</RoslynDirectoryName>
19-
20-
<!-- Otherwise, fallback to $(MSBuildBinPath)\Roslyn\ -->
21-
<RoslynDirectoryName Condition="$(RoslynDirectoryName) == ''">$([System.IO.Path]::Combine(`$(MSBuildBinPath)`,`Roslyn`))</RoslynDirectoryName>
22-
23-
<!-- Actually check that Microsoft.Build.Tasks.CodeAnalysis.dll exists at the resolved location.
24-
If it doesn't (eg. if the consuming project is a .wapproj project), remove the analyzer.
25-
In that case, the warning will also not be emitted, as there are no C# files to compile anyway. -->
26-
<RoslynAssemblyPath>$([System.IO.Path]::Combine(`$(RoslynDirectoryName)`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))</RoslynAssemblyPath>
27-
<IsRoslynAssemblyPresent Condition="$([System.IO.File]::Exists(`$(RoslynAssemblyPath)`)">true</IsRoslynAssemblyPresent>
28-
<IsRoslynAssemblyPresent Condition="$(IsRoslynAssemblyPresent) == ''">false</IsRoslynAssemblyPresent>
29-
</PropertyGroup>
30-
3115
<Choose>
32-
<When Condition="$(IsRoslynAssemblyPresent) == 'true'">
16+
<When Condition="$(CSharpCoreTargetsPath) != ''">
3317

3418
<!-- Use the CSharpCoreTargetsPath property to find the version of the compiler we are using. This is the same mechanism
3519
MSBuild uses to find the compiler. We could check the assembly version for any compiler assembly (since they all have
3620
the same version) but Microsoft.Build.Tasks.CodeAnalysis.dll is where MSBuild loads the compiler tasks from so if
3721
someone is getting creative with msbuild tasks/targets this is the "most correct" assembly to check. -->
38-
<GetAssemblyIdentity AssemblyFiles="$(RoslynAssemblyPath)">
22+
<GetAssemblyIdentity AssemblyFiles="$([System.IO.Path]::Combine(`$([System.IO.Path]::GetDirectoryName($(CSharpCoreTargetsPath)))`,`Microsoft.Build.Tasks.CodeAnalysis.dll`))">
3923
<Output TaskParameter="Assemblies" ItemName="CurrentCompilerAssemblyIdentity"/>
4024
</GetAssemblyIdentity>
4125

0 commit comments

Comments
 (0)