diff --git a/src/installer/pkg/sfx/installers/dnx b/src/installer/pkg/sfx/installers/dnx index b580e52192a7a7..511e7a05f0c3fd 100644 --- a/src/installer/pkg/sfx/installers/dnx +++ b/src/installer/pkg/sfx/installers/dnx @@ -15,6 +15,33 @@ done DIR="$(cd "$(dirname "$SCRIPT")" && pwd -P)" DOTNET="$DIR/dotnet" + +case "$1" in + /*|*/*) + case "$1" in + /*) DNX_FILE="$1" ;; + *) DNX_FILE="$PWD/$1" ;; + esac + + if [ -f "$DNX_FILE" ]; then + case "$DNX_FILE" in + *.[cC][sS]) IS_FILE_BASED_APP=true ;; + *) [ "$(dd if="$DNX_FILE" bs=2 count=1 2>/dev/null)" = "#!" ] && IS_FILE_BASED_APP=true ;; + esac + fi + ;; +esac + +if [ "$IS_FILE_BASED_APP" = true ]; then + DNX_WORKING_DIRECTORY="$PWD" + + if ! cd "$(dirname "$DNX_FILE")"; then + exit 1 + fi + + exec "$DOTNET" run --file-mode --working-directory "$DNX_WORKING_DIRECTORY" -- "$@" +fi + SDK_VERSION=$("$DOTNET" --list-sdks | tail -n 1 | cut -d' ' -f1) if [ -z "$SDK_VERSION" ]; then echo "Error: dnx requires a .NET SDK to be installed, but none was found." >&2 diff --git a/src/installer/pkg/sfx/installers/dnx.cmd b/src/installer/pkg/sfx/installers/dnx.cmd index 94156380edde6e..8609c2d76cfd78 100644 --- a/src/installer/pkg/sfx/installers/dnx.cmd +++ b/src/installer/pkg/sfx/installers/dnx.cmd @@ -6,6 +6,16 @@ setlocal enableextensions set "DOTNET=%~dp0dotnet.exe" +set "DNX_PATH=%~1" +if "%DNX_PATH:\=%"=="%DNX_PATH%" if "%DNX_PATH:/=%"=="%DNX_PATH%" goto run_tool +if not exist "%~f1" goto run_tool +if exist "%~f1\*" goto run_tool +if /I "%~x1"==".cs" goto run_file + +:check_shebang +for /f "delims=" %%i in ('findstr /n "^" "%~f1" 2^>nul ^| findstr /b /l /c:"1:#!"') do goto run_file + +:run_tool set "SDK_VERSION=" for /f "tokens=1" %%i in ('"%DOTNET%" --list-sdks') do ( set "SDK_VERSION=%%i" @@ -21,3 +31,13 @@ set "SDK_PATH=%~dp0sdk\%SDK_VERSION%\dotnet.dll" "%DOTNET%" exec "%SDK_PATH%" dnx %* endlocal & exit /b %ERRORLEVEL% + +:run_file +set "DNX_WORKING_DIRECTORY=%CD%" +pushd "%~dp1" || exit /b 1 + +"%DOTNET%" run --file-mode --working-directory "%DNX_WORKING_DIRECTORY%" -- %* +set "EXIT_CODE=%ERRORLEVEL%" + +popd +endlocal & exit /b %EXIT_CODE%