使用 Kudu 构建服务部署 asp.net 核心应用程序时出现 UnauthorizedAccessException

Getting UnauthorizedAccessException when deploying asp.net core app using Kudu build service

我已经使用 Kudu 构建服务(通过 GitHub 直接连接)设置了我的 aspnet core 2.2 应用程序的持续部署。直到前天还不错,但是从昨天开始我尝试部署任何东西时开始收到 UnauthorizedAccessException。但是我的应用程序没有任何变化。知道这里有什么问题吗??

这里是详细的异常:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling ASP.NET Core Web Application deployment.
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at Internal.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
   at Internal.Win32.RegistryKey.SetValue(String name, String value)
   at System.Environment.SetEnvironmentVariableFromRegistry(String variable, String value, Boolean fromMachine)
Failed exitCode=1, command=dotnet restore "D:\home\site\repository\myproject.sln"
   at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
An error has occurred during web site deployment.
   at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
   at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.\r\n   at Internal.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)\r\n   at Internal.Win32.RegistryKey.SetValue(String name, String value)\r\n   at System.Environment.SetEnvironmentVariableFromRegistry(String variable, String value, Boolean fromMachine)\r\n   at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)\r\n   at Microsoft.DotNet.Cli.Utils.EnvironmentProvider.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)\r\n   at Microsoft.DotNet.ShellShim.WindowsEnvironmentPath.AddPackageExecutablePathToUserPath()\r\n   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()\r\n   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel, IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, Boolean hasSuperUserAccess, DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IEnvironmentProvider environmentProvider)\r\n   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)\r\n   at Microsoft.DotNet.Cli.Program.Main(String[] args)\r\nD:\Program Files (x86)\SiteExtensions\Kudu.20224.4450\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

在 kudu 中尝试 "dotnet restore --help" 并得到相同的错误后,我意识到该错误与在 kudu 中执行 "dotnet restore" 而不是我的应用程序有关。 查看错误信息相关的代码后 https://github.com/dotnet/sdk/blob/5d747e7b4f1450a00eff5844bd76b73588531b2c/src/Cli/dotnet/Program.cs#L152 我意识到我可以通过添加名称为 DOTNET_ADD_GLOBAL_TOOLS_TO_PATH 且值为 false

的新应用程序设置来解决问题

Application setting

之后我可以像以前一样使用 kudu 部署我的应用程序。