Fix the batch file for running local dotnet on windows#23541
Merged
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).
Member
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jonathanpeppers
approved these changes
Jul 11, 2024
Comment on lines
4
to
+6
| 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%" |
Member
There was a problem hiding this comment.
@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?
Member
Author
There was a problem hiding this comment.
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).
PureWeen
approved these changes
Jul 11, 2024
Member
|
Failing test unrelated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
enabledelayedexpansionand 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
PATHcontains a parenthesis, the script would just plain fail (which can happen if one has x86 programs in their PATH).