Skip to content

Commit

Permalink
Fixed parsing DotNetMajor with preview sdks (#6012)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunghwan2789 authored and michaelstaib committed Apr 4, 2023
1 parent 31e4e45 commit 23b0554
Showing 1 changed file with 8 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
Outputs="$(MSBuildProjectDirectory)\$(IntermediateOutputPath)berry\.build.info"
Condition="'@(GraphQL)' != ''">

<DotNetMajor>
<Output TaskParameter="Major" PropertyName="DotNetMajor" />
</DotNetMajor>
<Exec Command="dotnet --version" StandardOutputImportance="Low" ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="DotNetVersion" />
</Exec>

<PropertyGroup>
<DotNetMajor Condition="$([MSBuild]::VersionGreaterThanOrEquals($(DotNetVersion), 6))">6</DotNetMajor>
<DotNetMajor Condition="$([MSBuild]::VersionGreaterThanOrEquals($(DotNetVersion), 7))">7</DotNetMajor>
</PropertyGroup>

<Error
Text="The Strawberry Shake code generation requires .NET SDK 6 or .NET SDK 7 to work."
Expand Down Expand Up @@ -66,40 +71,4 @@
<Touch Files="$(MSBuildProjectDirectory)\$(IntermediateOutputPath)berry\.build.info" AlwaysCreate="true" />
</Target>

<UsingTask
TaskName="DotNetMajor"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Major ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.Diagnostics"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var dotnetVersion = new ProcessStartInfo("dotnet", "--version")
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
};
var process = Process.Start(dotnetVersion);
if (process is not null)
{
var output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
if (process.ExitCode == 0 && Version.TryParse(output.Trim(), out var version))
{
Major = version.Major.ToString();
}
}
]]>
</Code>
</Task>
</UsingTask>

</Project>

0 comments on commit 23b0554

Please sign in to comment.