Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DotNet SDK support for versions less than 5 #3

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<ItemGroup>
<!--<Compile Update="**\*.cs" DependentUpon="I%(Filename).cs" />-->
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="all" Condition="!Exists('packages.config')" />
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
<PackageReference Include="stylecop.analyzers" Version="1.2.0-beta.507" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.3.0" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
</Project>
10 changes: 10 additions & 0 deletions build/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ public static async Task InstallDotNetSdk(this NukeBuild _, params string[] vers

foreach (var version in versionsToInstall.Select(arr => $"{arr[0]}.{arr[1]}.{arr[2].ToString().First().ToString()}xx").ToArray())
{
var v = version.Split('.').Take(2).Select(int.Parse).ToArray();
if (v?[0] < 5)
{
// Handle versions less than .Net 5.0 as only accepting 2 digits
var ver = $"{v[0]}.{v[1]}";
Console.WriteLine($"Installing .NET SDK {ver}");
ProcessTasks.StartShell($"powershell -NoProfile -ExecutionPolicy unrestricted -Command ./dotnet-install.ps1 -Channel '{ver}';").AssertZeroExitCode();
continue;
}

Console.WriteLine($"Installing .NET SDK {version}");
ProcessTasks.StartShell($"powershell -NoProfile -ExecutionPolicy unrestricted -Command ./dotnet-install.ps1 -Channel '{version}';").AssertZeroExitCode();
}
Expand Down
14 changes: 12 additions & 2 deletions src/CP.Nuke.BuildTools/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,23 @@ public static async Task InstallDotNetSdk(this NukeBuild _, params string[] vers

if (!File.Exists("dotnet-install.ps1"))
{
ProcessTasks.StartShell("powershell -NoProfile -ExecutionPolicy unrestricted -Command Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile 'dotnet-install.ps1';").AssertZeroExitCode();
ProcessTasks.StartShell("pwsh -NoProfile -ExecutionPolicy unrestricted -Command Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile 'dotnet-install.ps1';").AssertZeroExitCode();
}

foreach (var version in versionsToInstall.Select(arr => $"{arr[0]}.{arr[1]}.{arr[2].ToString().First().ToString()}xx").ToArray())
{
var v = version.Split('.').Take(2).Select(int.Parse).ToArray();
if (v?[0] < 5)
{
// Handle versions less than .Net 5.0 as only accepting 2 digits
var ver = $"{v[0]}.{v[1]}";
Console.WriteLine($"Installing .NET SDK {ver}");
ProcessTasks.StartShell($"pwsh -NoProfile -ExecutionPolicy unrestricted -Command ./dotnet-install.ps1 -Channel '{ver}';").AssertZeroExitCode();
continue;
}

Console.WriteLine($"Installing .NET SDK {version}");
ProcessTasks.StartShell($"powershell -NoProfile -ExecutionPolicy unrestricted -Command ./dotnet-install.ps1 -Channel '{version}';").AssertZeroExitCode();
ProcessTasks.StartShell($"pwsh -NoProfile -ExecutionPolicy unrestricted -Command ./dotnet-install.ps1 -Channel '{version}';").AssertZeroExitCode();
}

await Task.CompletedTask.ConfigureAwait(false);
Expand Down