Skip to content

Commit

Permalink
Fix version comparison and use built-in property
Browse files Browse the repository at this point in the history
The existing code would always fail the comparison becuase it was not done numerically, but as a string, resulting in 16.10 being smaller than 16.8. We fix it by parsing the full `MSBuildVersion` as a vesion instead, and comparing it to the minimum version (16.8) also parsed as a `Version` object.

Fixes #50
  • Loading branch information
kzu committed Mar 8, 2021
1 parent 88703e1 commit cb21dfa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<Project>

<PropertyGroup>
<MSBuildShortVersion>$(MSBuildVersion.TrimEnd('0123456789').TrimEnd('.'))</MSBuildShortVersion>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="DebugSourceGenerators" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project>

<Target Name="EnsureSourceGenerators" BeforeTargets="BeforeCompile;CoreCompile">

<Error Text="ThisAssembly requires MSBuild 16.8+ or .NET SDK 5.0+."
Condition="$(MSBuildShortVersion) &lt; '16.8'" />
Condition="$([System.Version]::Parse('16.8.0').CompareTo($([System.Version]::Parse($(MSBuildVersion))))) == 1" />

<!-- See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/langversion-compiler-option -->
<Error Text="ThisAssembly uses Roslyn source generators, which are only supported in C# 9.0 or greater at the moment."
Condition="'$(Language)' != 'C#' OR
Expand Down

0 comments on commit cb21dfa

Please sign in to comment.