Skip to content

Fix the batch file for running local dotnet on windows#23541

Merged
PureWeen merged 1 commit into
dotnet:mainfrom
vitek-karas:fixdotnetlocalwindowsmain
Jul 11, 2024
Merged

Fix the batch file for running local dotnet on windows#23541
PureWeen merged 1 commit into
dotnet:mainfrom
vitek-karas:fixdotnetlocalwindowsmain

Conversation

@vitek-karas

Copy link
Copy Markdown
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
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

Comment thread dotnet-local.cmd
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Failing test unrelated

@PureWeen PureWeen merged commit 6618fe6 into dotnet:main Jul 11, 2024
@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