Skip to content

Commit

Permalink
Fix the batch file for running local dotnet on windows (#23541)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
vitek-karas authored Jul 11, 2024
1 parent f19f9cf commit 6618fe6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dotnet-local.cmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@echo off
setlocal enabledelayedexpansion
SET ROOT=%~dp0
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%"
call "%ROOT%\bin\dotnet\dotnet.exe" %*
) ELSE (
echo "You must build MAUI first. Please see '.github/DEVELOPMENT.md' for details."
Expand Down

0 comments on commit 6618fe6

Please sign in to comment.