Skip to content

Commit

Permalink
fix: #806 CommandService couldn't find dotnet executable's path on linux
Browse files Browse the repository at this point in the history
Signed-off-by: MTsfoni <[email protected]>
  • Loading branch information
mtsfoni committed Dec 29, 2023
1 parent 35d161f commit 34cc4e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions CycloneDX/Services/DotnetCommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static string GetDotnetPathOrDefault()
fileName += ".exe";
}
var mainModule = Process.GetCurrentProcess().MainModule;
if (!string.IsNullOrEmpty(mainModule.FileName)
if (!string.IsNullOrEmpty(mainModule?.FileName)
&& Path.GetFileName(mainModule.FileName).Equals(fileName, StringComparison.OrdinalIgnoreCase))
{
return mainModule.FileName;
Expand All @@ -105,13 +105,32 @@ private static string GetDotnetPathOrDefault()
{
// fall back to default location
// https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_root-dotnet_rootx86
dotnetRoot = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:\\Program Files\\dotnet" : "/usr/local/share/dotnet";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
dotnetRoot = "C:\\Program Files\\dotnet";

}
else
{
dotnetRoot = "/usr/local/share/dotnet";
if (!Directory.Exists(dotnetRoot))
{
dotnetRoot = "/usr/share/dotnet";
}
if (!Directory.Exists(dotnetRoot))
{
dotnetRoot = "/usr/lib/dotnet";
}
}


}

return Path.Combine(dotnetRoot, fileName);
}

private static async Task ConsumeStreamReaderAsync(StreamReader reader, StringBuilder lines)
private static async Task ConsumeStreamReaderAsync(StreamReader reader, StringBuilder lines)
{
await Task.Yield();

Expand Down
2 changes: 1 addition & 1 deletion semver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.0.1

0 comments on commit 34cc4e5

Please sign in to comment.