Skip to content

Find correct x64 host on arm64 machines #207

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

Merged
merged 3 commits into from
Jun 14, 2022

Conversation

NikolaMilosavljevic
Copy link
Member

Fixes: #138

Launcher will find proper x64 host location on arm64 machines.

Since .NET 6, x64 .NET, on arm64 systems, is installed to \Program Files\dotnet\x64.

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some suggestions. Also cc @MarcoRossignoli and @vitek-karas for best practice on locating dotnet as I believe they have components which also do this.

@MarcoRossignoli
Copy link
Member

We don't have a specific component but we implemented the search for the --arch feature here https://github.com/microsoft/vstest/blob/main/src/Microsoft.TestPlatform.CoreUtilities/Helpers/DotnetHostHelper.cs#L123

@@ -69,18 +110,26 @@ private static string GetProgramFilesFolder(bool is64bit = false)
/// </summary>
/// <param name="is64bit">If 64-bit bitness is required</param>
/// <returns></returns>
private static string GetGlobalHost(bool is64bit = false)
private string GetGlobalHost(bool is64bit = false)
{
string folder = GetProgramFilesFolder(is64bit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not related to this PR exactly, but this is technically wrong. There's no guarantee that the runtime will be in program files. Ever since 3.1 we added the ability to install to custom "global" location and the location is written in registry. See this doc for the arch specific details: https://github.com/dotnet/designs/blob/main/accepted/2021/install-location-per-architecture.md
and this for the "custom global location" details: https://github.com/dotnet/designs/blob/main/accepted/2020/install-locations.md

Copy link
Member Author

@NikolaMilosavljevic NikolaMilosavljevic Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is a known issue. I have called this out in the comments, in this source file. We do not currently support custom global host locations, but I believe this will be done before 7.0 RTM.

/// Current code searches in default, global shared runtime, location only:
/// %ProgramFiles%\dotnet and %ProgramFiles(x86)%\dotnet
///
/// Consider adding support for other non-standard registrations of host location.
/// 1) Environment variables: DOTNET_ROOT or DOTNET_ROOT(x86)
/// 2) Registry: HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\{arch}\[InstallLocation]

@vitek-karas
Copy link
Member

{
get
{
string proc = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture instead of the environment variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture instead of the environment variable?

It seems that the API returns architecture of the currently running app: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.runtimeinformation.processarchitecture?view=net-6.0&viewFallbackFrom=netframework-4.6.2#system-runtime-interopservices-runtimeinformation-processarchitecture

For ClickOnce deployment, this is not guaranteed to match the OS architecture, even though Launcher is built as MSIL.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For OS Architecture, there is the RuntimeInformation.OSArchitecture property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For OS Architecture, there is the RuntimeInformation.OSArchitecture property.

That property is available in v4.7.1 and later. Launcher targets v4.5, to ensure we can run on as many systems as possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed the commit that fixes this.

{
try
{
if (NativeMethods.Kernel32.IsWow64Process2(new IntPtr(-1), out _, out ushort nativeMachine))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call GetCurrentProcess instead of hardcoding to -1?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize it will return a pseudo handle of -1 also.

@NikolaMilosavljevic NikolaMilosavljevic merged commit e22a6e2 into dotnet:main Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong host location is found for x64 on ARM64
5 participants