错误 - 访问被拒绝 - 部署到 Azure 应用服务

Error - Access is denied - deployment to Azure App Services

我们通过 KUDU 脚本在 Azure 中使用自动部署过程,今天我们在 Azure 部署中心看到奇怪的错误:

命令 dotnet publish(还有 'dotnet build')returns:

MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
Unhandled exception. System.ComponentModel.Win32Exception (5): Access is denied.
System.ComponentModel.Win32Exception (5): Access is denied.
   at System.Diagnostics.Process.set_PriorityClassCore(ProcessPriorityClass value)
   at System.Diagnostics.Process.set_PriorityClass(ProcessPriorityClass value)
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
   at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args)
   at System.Diagnostics.Process.set_PriorityClassCore(ProcessPriorityClass value)
   at System.Diagnostics.Process.set_PriorityClass(ProcessPriorityClass value)
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
Failed exitCode=-532462766, command=dotnet publish "D:\home\site\repository\
...

详情:

问题可能出在 Azure 方面,因为我们没有对项目做任何更大的更改。 有人 same/similar 有问题吗?

我们遇到了同样的问题,经过调查我们发现:

  • Azure 应用了新的 'dotnet' 版本 3.1.301,此版本的 SDK 会抛出该错误(您可以通过 commnad 'dotnet --version' 检查您的版本)
  • 通过命令'dotnet --list-sdks'可以看到所有安装的SDK
  • 然后我们简单地使用以前的版本(在我们的例子中是 v3.1.202)
  • 如何判断 dotnet sdk 的确切版本的最简单方法是 global.json

示例: global.json

{
  "sdk": {
    "version": "3.1.202"
  }
}

并且文件必须在 'working directory',KUDU 脚本的工作目录在这里 D:\home\site\repository

当您在以前版本的 dotnet SDK 上部署正常时,这肯定会有所帮助。

这个问题也可能在其他情况下发生,因为 sdk 是作为管理员安装的(例如,如果使用 sudo 安装)。 在这种情况下,卸载 sdk 并将其安装为 non-admin 用户可以帮助解决问题。您可以使用 this script 为 non-admin 用户安装。

例如(在 ubuntu 20.04 上测试):

$ wget https://dot.net/v1/dotnet-install.sh
$ chmod +x dotnet-install.sh
$ ./dotnet-install.sh -c Current

添加到路径并验证:

$ echo "export PATH=$HOME/.dotnet:$PATH" >> ~/.bashrc
$ exec bash
$ dotnet --version
3.1.402

注意:执行此操作后,您可能会收到错误 error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock 然后您可以将其删除,一切顺利。

sudo rm -r /tmp/NuGet*