-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix the batch file for running local dotnet on windows #23541
Conversation
The problem was that the body of the IF statement is considered one "line" and all environment variables are replaced before that "line" is executed. So set commands don't have an effect on the rest of the code in that IF. Changed this to use `enabledelayedexpansion` and the `!!` syntax which makes it work the way would would expect. One additional fix, enclose the set commands in quotation marks. This fixes a bug where if the `PATH` contains a parenthesis, the script would just plain fail (which can happen if one has x86 programs in their PATH).
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
IF EXIST "%ROOT%\bin\dotnet\dotnet.exe" ( | ||
SET DOTNET_ROOT=%ROOT%\bin\dotnet | ||
SET PATH=%DOTNET_ROOT%;%PATH% | ||
SET "DOTNET_ROOT=%ROOT%\bin\dotnet" | ||
SET "PATH=!DOTNET_ROOT!;%PATH%" |
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.
@vitek-karas do we have any similar problems here?
https://github.com/dotnet/android/blob/main/dotnet-local.cmd
Or is it fine? Because there are not multiple lines inside an IF
?
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.
That should be fine - the problem is that the parser considers the entire IF as one statement and performs env. variable replacement BEFORE it executes the statement. Any changes to the environment are not visible to the statements inside the IF, but they are visible to external tools (so in this case the dotnet.exe
will see the new values as expected).
Failing test unrelated |
The problem was that the body of the IF statement is considered one "line" and all environment variables are replaced before that "line" is executed. So set commands don't have an effect on the rest of the code in that IF. Changed this to use
enabledelayedexpansion
and the!!
syntax which makes it work the way would expect.One additional fix, enclose the set commands in quotation marks. This fixes a bug where if the
PATH
contains a parenthesis, the script would just plain fail (which can happen if one has x86 programs in their PATH).