-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Mono: Improve MSBuildFinder logic on Windows #41375
Conversation
Does this fix something specific, or is it a proofreading change? If the latter, I think the logic is that "ProgramFiles(x86)" is the name of the 32-bit install path on 64-bit systems, so the current logic is correct. CC @neikeq |
I'm not sure but as for me, My machine is windows x64 but I have no When I change it like this then it fixed If that was your logic then it sound reasonable. I would retract this request |
On another thought. I think it would be better if we will always try to find from both place, how about this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised about this as I thought this was guaranteed to always be on the 32-bit install location, but I guess that's not the case.
Some corrections are needed though.
string vsWherePath = null; | ||
foreach(var envName in envNames) | ||
{ | ||
vsWherePath = Environment.GetEnvironmentVariable(Internal.GodotIs32Bits() ? "ProgramFiles(x86)" : "ProgramFiles"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
vsWherePath = Environment.GetEnvironmentVariable(Internal.GodotIs32Bits() ? "ProgramFiles(x86)" : "ProgramFiles"); | |
vsWherePath = Environment.GetEnvironmentVariable(envName); |
@@ -161,8 +161,21 @@ private static string FindMsBuildToolsPathOnWindows() | |||
|
|||
// Try to find 15.0 with vswhere | |||
|
|||
string vsWherePath = Environment.GetEnvironmentVariable(Internal.GodotIs32Bits() ? "ProgramFiles" : "ProgramFiles(x86)"); | |||
vsWherePath += "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; | |||
var envNames = Internal.GodotIs32Bits() ? new[] { "ProgramFiles","ProgramFiles(x86)" } : new[] { "ProgramFiles(x86)","ProgramFiles" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no ProgramFiles(x86)
on 32-bit Windows AFAIK:
var envNames = Internal.GodotIs32Bits() ? new[] { "ProgramFiles","ProgramFiles(x86)" } : new[] { "ProgramFiles(x86)","ProgramFiles" }; | |
var envNames = Internal.GodotIs32Bits() ? new[] { "ProgramFiles" } : new[] { "ProgramFiles(x86)","ProgramFiles" }; |
Also the code needs to be reformatted to follow the C# style guidelines. Spaces between |
Could you squash commits into one and make the commit message more explicit about what it does? |
I can't. I have edit this with github directly, not from my local |
break; | ||
} | ||
|
||
vsWherePath = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this is reached? What's the result of Godot.OS.Execute(null, ...)
? @neikeq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same as passing an empty string. OS.execute may print an error. Albeit to be fair the old code didn't check if vsWherePath
existed in the file system either.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will there be any possible chance that someone would install their vs installer outside of ProgramFiles and just directly in the drive though?
modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
Outdated
Show resolved
Hide resolved
vsWherePath = Environment.GetEnvironmentVariable(envName); | ||
if (!string.IsNullOrEmpty(vsWherePath)) | ||
{ | ||
vsWherePath += "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly about this PR's changes, but can we just use /
for the directory separator on Windows in the C# code? Windows has supported /
as a directory separator for decades now, and I think all of the tooling that Godot uses supports it.
@@ -161,8 +161,21 @@ private static string FindMsBuildToolsPathOnWindows() | |||
|
|||
// Try to find 15.0 with vswhere | |||
|
|||
string vsWherePath = Environment.GetEnvironmentVariable(Internal.GodotIs32Bits() ? "ProgramFiles" : "ProgramFiles(x86)"); | |||
vsWherePath += "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; | |||
var envNames = Internal.GodotIs32Bits() ? new[] { "ProgramFiles", "ProgramW6432" } : new[] { "ProgramFiles(x86)", "ProgramFiles" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense to check the matching architecture's path first? This would mean that the "ProgramFiles"
environment variable is checked first, since for a 32-bit process it points to 32-bit Program Files, and for a 64-bit process it points to 64-bit Program Files.
var envNames = Internal.GodotIs32Bits() ? new[] { "ProgramFiles", "ProgramW6432" } : new[] { "ProgramFiles(x86)", "ProgramFiles" }; | |
var envNames = Internal.GodotIs32Bits() ? new[] { "ProgramFiles", "ProgramW6432" } : new[] { "ProgramFiles", "ProgramFiles(x86)" }; |
We might be able to optimize this further by only changing the fallback environment variable. I haven't compiled this but I wonder if this works:
var envNames = Internal.GodotIs32Bits() ? new[] { "ProgramFiles", "ProgramW6432" } : new[] { "ProgramFiles(x86)", "ProgramFiles" }; | |
var envNames = new[] { "ProgramFiles", Internal.GodotIs32Bits() ? "ProgramW6432" : "ProgramFiles(x86)" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I have heard is, in windows 64 bit, Visual Studio Installer most likely be installed in ProgramFiles(x86)
by default. Only me or some people that change the default path of installer would met this problem. So I think it would be more efficient to ordering this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm just thinking of future proofing it, in case there is a 64-bit Visual Studio Installer in the future and then it would be placed in the 64-bit folder instead (and if both exist, 64-bit Godot would prefer the 64-bit one). I'll let @neikeq decide what's best here.
Support detecting both 32-bit and 64-bit installations of `vswhere.exe`.
Force pushed to squash commits and make the commit message clearer. |
Thanks! |
@akien-mga Could this also picked into 3.2 branch? I currently only able to use that branch |
|
Sorry then, Yesterday I try to pull 3.2 branch and this code are not in there yet |
Cherry-picked for 3.2.3. |
Shouldn't 32bit path be x86 ?