Skip to content
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

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

vitek-karas
Copy link
Member

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).

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).
@vitek-karas vitek-karas self-assigned this Jul 10, 2024
@vitek-karas vitek-karas requested a review from a team as a code owner July 10, 2024 15:06
@PureWeen PureWeen requested review from jonathanpeppers and removed request for jfversluis July 11, 2024 00:42
@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

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%"
Copy link
Member

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?

Copy link
Member Author

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).

@PureWeen
Copy link
Member

Failing test unrelated

@PureWeen PureWeen merged commit 6618fe6 into dotnet:main Jul 11, 2024
95 of 97 checks passed
@vitek-karas vitek-karas deleted the fixdotnetlocalwindowsmain branch July 11, 2024 14:31
@samhouts samhouts added fixed-in-net9.0-nightly This may be available in a nightly release! fixed-in-net8.0-nightly This may be available in a nightly release! fixed-in-8.0.80 and removed fixed-in-net9.0-nightly This may be available in a nightly release! fixed-in-net8.0-nightly This may be available in a nightly release! labels Aug 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-8.0.80 fixed-in-net9.0-nightly This may be available in a nightly release!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants