如何更新 Azure Function 中的 dotnet 核心版本
How to Update the dotnet core version in Azure Function
我正在为我的 dotnet 3.1 函数应用程序构建一个 kudo,下面是我的 kudo 构建脚本
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
:: ----------------------
:: KUDU Deployment Script
:: Version: 1.0.17
:: ----------------------
:: Prerequisites
:: -------------
:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
goto error
)
:: Setup
:: -----
setlocal enabledelayedexpansion
SET ARTIFACTS=%~dp0%..\artifacts
IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%~dp0%.
)
IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)
IF NOT DEFINED NEXT_MANIFEST_PATH (
SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest
IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
)
)
IF NOT DEFINED KUDU_SYNC_CMD (
:: Install kudu sync
echo Installing Kudu Sync
call npm install kudusync -g --silent
IF !ERRORLEVEL! NEQ 0 goto error
:: Locally just running "kuduSync" would also work
SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
)
IF NOT DEFINED DEPLOYMENT_TEMP (
SET DEPLOYMENT_TEMP=%temp%\___deployTemp%random%
SET CLEAN_LOCAL_DEPLOYMENT_TEMP=true
)
IF DEFINED CLEAN_LOCAL_DEPLOYMENT_TEMP (
IF EXIST "%DEPLOYMENT_TEMP%" rd /s /q "%DEPLOYMENT_TEMP%"
mkdir "%DEPLOYMENT_TEMP%"
)
IF DEFINED MSBUILD_PATH goto MsbuildPathDefined
SET MSBUILD_PATH=%ProgramFiles(x86)%\MSBuild.0\Bin\MSBuild.exe
:MsbuildPathDefined
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------
echo Handling .NET Web Application deployment.
:: 1. Restore NuGet packages
call :ExecuteCmd dotnet restore "%DEPLOYMENT_SOURCE%\dotnetcore-app.sln"
IF !ERRORLEVEL! NEQ 0 goto error
:: 2. Build to the temporary path
call :ExecuteCmd dotnet publish "%DEPLOYMENT_SOURCE%\dotnetcore-app.sln" --output "%DEPLOYMENT_TEMP%" /p:Configuration=Release
IF !ERRORLEVEL! NEQ 0 goto error
:: 5. KuduSync
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
IF !ERRORLEVEL! NEQ 0 goto error
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end
:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%
:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul
:exitSetErrorLevel
exit /b 1
:exitFromFunction
()
:end
endlocal
echo Finished successfully.
这里的问题是 kudo 构建默认会说话 dotnet 5.0.204
,但我需要使用 3.1.116
SDK
remote: Handling .NET Web Application deployment.
remote: Failed to add 'C:\local\UserProfile\.dotnet\tools' to the PATH environment variable. Add this directory to your PATH to use tools installed with 'dotnet tool install'.
remote:
remote: Welcome to .NET 5.0!
remote: ---------------------
remote: SDK Version: 5.0.204
remote:
remote: Telemetry
remote: ---------
remote: The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
remote:
remote: Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
remote:
remote: ----------------
remote: Installed an ASP.NET Core HTTPS development certificate.
remote: To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
remote: Learn about HTTPS: https://aka.ms/dotnet-https
remote: ----------------
remote: Write your first app: https://aka.ms/dotnet-hello-world
remote: Find out what's new: https://aka.ms/dotnet-whats-new
remote: Explore documentation: https://aka.ms/dotnet-docs
remote: Report issues and find source on GitHub: https://github.com/dotnet/core
我可以看到函数应用程序已经安装了下面的 sdk 列表
C:\home\site\wwwroot>dotnet --list-sdks
1.1.14 [C:\Program Files (x86)\dotnet\sdk]
2.1.522 [C:\Program Files (x86)\dotnet\sdk]
2.2.109 [C:\Program Files (x86)\dotnet\sdk]
3.1.113 [C:\Program Files (x86)\dotnet\sdk]
3.1.115 [C:\Program Files (x86)\dotnet\sdk]
3.1.116 [C:\Program Files (x86)\dotnet\sdk]
5.0.201 [C:\Program Files (x86)\dotnet\sdk]
5.0.203 [C:\Program Files (x86)\dotnet\sdk]
5.0.204 [C:\Program Files (x86)\dotnet\sdk]
问题:如何将函数中的 dotnet 版本更改为默认 3.1
而不是 5.0
?
我已经通过提供无效的 sdk 版本尝试了 global.json
我正在为我的 dotnet 3.1 函数应用程序构建一个 kudo,下面是我的 kudo 构建脚本
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
:: ----------------------
:: KUDU Deployment Script
:: Version: 1.0.17
:: ----------------------
:: Prerequisites
:: -------------
:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
goto error
)
:: Setup
:: -----
setlocal enabledelayedexpansion
SET ARTIFACTS=%~dp0%..\artifacts
IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%~dp0%.
)
IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)
IF NOT DEFINED NEXT_MANIFEST_PATH (
SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest
IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
)
)
IF NOT DEFINED KUDU_SYNC_CMD (
:: Install kudu sync
echo Installing Kudu Sync
call npm install kudusync -g --silent
IF !ERRORLEVEL! NEQ 0 goto error
:: Locally just running "kuduSync" would also work
SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
)
IF NOT DEFINED DEPLOYMENT_TEMP (
SET DEPLOYMENT_TEMP=%temp%\___deployTemp%random%
SET CLEAN_LOCAL_DEPLOYMENT_TEMP=true
)
IF DEFINED CLEAN_LOCAL_DEPLOYMENT_TEMP (
IF EXIST "%DEPLOYMENT_TEMP%" rd /s /q "%DEPLOYMENT_TEMP%"
mkdir "%DEPLOYMENT_TEMP%"
)
IF DEFINED MSBUILD_PATH goto MsbuildPathDefined
SET MSBUILD_PATH=%ProgramFiles(x86)%\MSBuild.0\Bin\MSBuild.exe
:MsbuildPathDefined
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------
echo Handling .NET Web Application deployment.
:: 1. Restore NuGet packages
call :ExecuteCmd dotnet restore "%DEPLOYMENT_SOURCE%\dotnetcore-app.sln"
IF !ERRORLEVEL! NEQ 0 goto error
:: 2. Build to the temporary path
call :ExecuteCmd dotnet publish "%DEPLOYMENT_SOURCE%\dotnetcore-app.sln" --output "%DEPLOYMENT_TEMP%" /p:Configuration=Release
IF !ERRORLEVEL! NEQ 0 goto error
:: 5. KuduSync
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
IF !ERRORLEVEL! NEQ 0 goto error
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end
:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%
:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul
:exitSetErrorLevel
exit /b 1
:exitFromFunction
()
:end
endlocal
echo Finished successfully.
这里的问题是 kudo 构建默认会说话 dotnet 5.0.204
,但我需要使用 3.1.116
SDK
remote: Handling .NET Web Application deployment.
remote: Failed to add 'C:\local\UserProfile\.dotnet\tools' to the PATH environment variable. Add this directory to your PATH to use tools installed with 'dotnet tool install'.
remote:
remote: Welcome to .NET 5.0!
remote: ---------------------
remote: SDK Version: 5.0.204
remote:
remote: Telemetry
remote: ---------
remote: The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
remote:
remote: Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
remote:
remote: ----------------
remote: Installed an ASP.NET Core HTTPS development certificate.
remote: To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
remote: Learn about HTTPS: https://aka.ms/dotnet-https
remote: ----------------
remote: Write your first app: https://aka.ms/dotnet-hello-world
remote: Find out what's new: https://aka.ms/dotnet-whats-new
remote: Explore documentation: https://aka.ms/dotnet-docs
remote: Report issues and find source on GitHub: https://github.com/dotnet/core
我可以看到函数应用程序已经安装了下面的 sdk 列表
C:\home\site\wwwroot>dotnet --list-sdks
1.1.14 [C:\Program Files (x86)\dotnet\sdk]
2.1.522 [C:\Program Files (x86)\dotnet\sdk]
2.2.109 [C:\Program Files (x86)\dotnet\sdk]
3.1.113 [C:\Program Files (x86)\dotnet\sdk]
3.1.115 [C:\Program Files (x86)\dotnet\sdk]
3.1.116 [C:\Program Files (x86)\dotnet\sdk]
5.0.201 [C:\Program Files (x86)\dotnet\sdk]
5.0.203 [C:\Program Files (x86)\dotnet\sdk]
5.0.204 [C:\Program Files (x86)\dotnet\sdk]
问题:如何将函数中的 dotnet 版本更改为默认 3.1
而不是 5.0
?
我已经通过提供无效的 sdk 版本尝试了 global.json