Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/installer/pkg/sfx/installers/dnx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +35 to +43

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
Expand Down
20 changes: 20 additions & 0 deletions src/installer/pkg/sfx/installers/dnx.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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%"
Comment on lines +35 to +40

popd
endlocal & exit /b %EXIT_CODE%
Loading