Skip to content

Commit

Permalink
Fix platform checks
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed May 18, 2024
1 parent a44aa9b commit a182982
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
41 changes: 23 additions & 18 deletions src/AspireRunner.Core/AspireDashboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,31 @@ private void ResetErrorLogDelay()

private static void LaunchBrowser(string url)
{
#if windows
Process.Start(new ProcessStartInfo
if (OperatingSystem.IsWindows())
{
UseShellExecute = true,
FileName = url
});
#elif linux
Process.Start(new ProcessStartInfo
Process.Start(new ProcessStartInfo
{
UseShellExecute = true,
FileName = url
});
}
else if (OperatingSystem.IsLinux())
{
FileName = "xdg-open",
UseShellExecute = true,
Arguments = $"\"{url}\""
});
#elif macos
Process.Start(new ProcessStartInfo
Process.Start(new ProcessStartInfo
{
FileName = "xdg-open",
UseShellExecute = true,
Arguments = $"\"{url}\""
});
}
else if (OperatingSystem.IsMacOS())
{
FileName = "open",
UseShellExecute = true,
Arguments = $"\"{url}\""
});
#endif
Process.Start(new ProcessStartInfo
{
FileName = "open",
UseShellExecute = true,
Arguments = $"\"{url}\""
});
}
}
}
19 changes: 1 addition & 18 deletions src/AspireRunner.Core/AspireRunner.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>

Expand Down Expand Up @@ -35,21 +35,4 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0"/>
<PackageReference Include="SemanticVersioning" Version="2.0.2"/>
</ItemGroup>

<PropertyGroup>
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
</PropertyGroup>

<PropertyGroup Condition="'$(IsWindows)'=='true'">
<DefineConstants>windows</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsOSX)'=='true'">
<DefineConstants>macos</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsLinux)'=='true'">
<DefineConstants>linux</DefineConstants>
</PropertyGroup>

</Project>
18 changes: 7 additions & 11 deletions src/AspireRunner.Core/DotnetCli.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace AspireRunner.Core;

public partial class DotnetCli
{
public const string DataFolderName = ".dotnet";
#if windows
public const string Executable = "dotnet.exe";
#else
public const string Executable = "dotnet";
#endif

public static readonly string Executable = OperatingSystem.IsWindows() ? "dotnet.exe" : "dotnet";

public string CliPath { get; private init; } = null!;

Expand All @@ -21,10 +17,10 @@ public partial class DotnetCli
private DotnetCli() { }

/// <summary>
/// Creates a new instance of the <see cref="DotnetCli"/> class.
/// Creates a new instance of the <see cref="AspireRunner.Core.DotnetCli"/> class.
/// </summary>
/// <returns>
/// A new instance of the <see cref="DotnetCli"/> class or null if the dotnet CLI wasn't found.
/// A new instance of the <see cref="AspireRunner.Core.DotnetCli"/> class or null if the dotnet CLI wasn't found.
/// </returns>
public static DotnetCli? TryCreate()
{
Expand Down Expand Up @@ -231,7 +227,7 @@ private static string GetOrCreateDataPath()
return Path.GetDirectoryName(dotnetPath);
}

var paths = GetEnvPath();
var paths = GetEnvPaths();
foreach (var path in paths)
{
dotnetPath = Path.Combine(path, Executable);
Expand All @@ -249,7 +245,7 @@ private static string GetOrCreateDataPath()
/// </summary>
/// <returns>A string array containing all paths in the system's <c>PATH</c> environment variable.</returns>
/// <remarks>When running inside WSL, windows paths (like <c>/mnt/c/*</c>) will be excluded to avoid conflicts with windows dotnet installations</remarks>
private static string[] GetEnvPath()
private static string[] GetEnvPaths()
{
var pathEnv = Environment.GetEnvironmentVariable("PATH");
if (string.IsNullOrWhiteSpace(pathEnv))
Expand All @@ -274,7 +270,7 @@ private static string[] GetEnvPath()
/// <returns>True if the current process is running inside WSL, false otherwise.</returns>
private static bool IsRunningWsl()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (!OperatingSystem.IsLinux())
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AspireRunner.Tool/AspireRunner.Tool.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
Expand Down

0 comments on commit a182982

Please sign in to comment.