diff --git a/dotnet/src/Client.cs b/dotnet/src/Client.cs index 15b00ec79..225b893c6 100644 --- a/dotnet/src/Client.cs +++ b/dotnet/src/Client.cs @@ -997,11 +997,32 @@ private async Task VerifyProtocolVersionAsync(Connection connection, Cancellatio private static string? GetBundledCliPath(out string searchedPath) { var binaryName = OperatingSystem.IsWindows() ? "copilot.exe" : "copilot"; - var rid = Path.GetFileName(System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier); + // Always use portable RID (e.g., linux-x64) to match the build-time placement, + // since distro-specific RIDs (e.g., ubuntu.24.04-x64) are normalized at build time. + var rid = GetPortableRid() + ?? Path.GetFileName(System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier); searchedPath = Path.Combine(AppContext.BaseDirectory, "runtimes", rid, "native", binaryName); return File.Exists(searchedPath) ? searchedPath : null; } + private static string? GetPortableRid() + { + string os; + if (OperatingSystem.IsWindows()) os = "win"; + else if (OperatingSystem.IsLinux()) os = "linux"; + else if (OperatingSystem.IsMacOS()) os = "osx"; + else return null; + + var arch = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture switch + { + System.Runtime.InteropServices.Architecture.X64 => "x64", + System.Runtime.InteropServices.Architecture.Arm64 => "arm64", + _ => null, + }; + + return arch != null ? $"{os}-{arch}" : null; + } + private static (string FileName, IEnumerable Args) ResolveCliCommand(string cliPath, IEnumerable args) { var isJsFile = cliPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase); diff --git a/dotnet/src/build/GitHub.Copilot.SDK.targets b/dotnet/src/build/GitHub.Copilot.SDK.targets index 20afd8156..35b017662 100644 --- a/dotnet/src/build/GitHub.Copilot.SDK.targets +++ b/dotnet/src/build/GitHub.Copilot.SDK.targets @@ -3,17 +3,27 @@ - + - <_CopilotRid Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier) - <_CopilotRid Condition="'$(_CopilotRid)' == '' And $([MSBuild]::IsOSPlatform('Windows')) And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">win-x64 - <_CopilotRid Condition="'$(_CopilotRid)' == '' And $([MSBuild]::IsOSPlatform('Windows')) And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">win-arm64 - <_CopilotRid Condition="'$(_CopilotRid)' == '' And $([MSBuild]::IsOSPlatform('Linux')) And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">linux-x64 - <_CopilotRid Condition="'$(_CopilotRid)' == '' And $([MSBuild]::IsOSPlatform('Linux')) And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">linux-arm64 - <_CopilotRid Condition="'$(_CopilotRid)' == '' And $([MSBuild]::IsOSPlatform('OSX')) And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">osx-x64 - <_CopilotRid Condition="'$(_CopilotRid)' == '' And $([MSBuild]::IsOSPlatform('OSX')) And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">osx-arm64 + + <_CopilotOs Condition="'$(RuntimeIdentifier)' != '' And $(RuntimeIdentifier.StartsWith('win'))">win + <_CopilotOs Condition="'$(_CopilotOs)' == '' And '$(RuntimeIdentifier)' != '' And $(RuntimeIdentifier.StartsWith('osx'))">osx + <_CopilotOs Condition="'$(_CopilotOs)' == '' And '$(RuntimeIdentifier)' != ''">linux + + + <_CopilotArch Condition="'$(RuntimeIdentifier)' != '' And $(RuntimeIdentifier.EndsWith('-x64'))">x64 + <_CopilotArch Condition="'$(_CopilotArch)' == '' And '$(RuntimeIdentifier)' != '' And $(RuntimeIdentifier.EndsWith('-arm64'))">arm64 + + + <_CopilotRid Condition="'$(_CopilotOs)' != '' And '$(_CopilotArch)' != ''">$(_CopilotOs)-$(_CopilotArch) + <_CopilotRid Condition="'$(_CopilotRid)' == '' And '$(RuntimeIdentifier)' == ''">$(NETCoreSdkPortableRuntimeIdentifier) + + + + + <_CopilotPlatform Condition="'$(_CopilotRid)' == 'win-x64'">win32-x64