Azure Linux WebApp 上的 ASP.NET Core NodeServices [英] ASP.NET Core NodeServices on Azure Linux WebApp
问题描述
我习惯于在 Windows 上发布 Azure WebApp,但现在我尝试将 ASP.NET Core 3(带有 NodeServices)部署到 Linux WebApp,我收到以下错误消息:
I am used to publish Azure WebApps on Windows but now I am trying to deploy an ASP.NET Core 3 (with NodeServices) to a Linux WebApp and I am receiving the following error message:
InvalidOperationException:无法启动节点进程.要解决这个问题:.
[1] 确保 Node.js 已安装并且可以在 PATH 目录之一中找到.当前 PATH 环境变量是:/opt/dotnetcore-tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/site/wwwroot确保 Node 可执行文件位于这些目录之一中,或更新您的 PATH.
[1] Ensure that Node.js is installed and can be found in one of the PATH directories. Current PATH enviroment variable is: /opt/dotnetcore-tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/site/wwwroot Make sure the Node executable is in one of those directories, or update your PATH.
在 Windows WebApps 上,我有很多其他应用程序,一切都很好.
On Windows WebApps I have a lot of other apps and all are fine.
在 Kudu 上,我输入了 node -v
,输出为 v12.13.0
.
On Kudu I typed node -v
and the output was v12.13.0
.
谁能帮帮我?
非常感谢.
推荐答案
经过长期研究和微软工程师的协助https://github.com/caroe2014 这是最终答案的三个步骤:
After a long research and the assistance of Microsoft's Engineer https://github.com/caroe2014 this is the three steps final answer:
1) Startup.cs
1) Startup.cs
services.AddNodeServices(options =>
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
options.ProjectPath = Path.GetFullPath("/home/site/wwwroot");
}
}
);
2) 我发现容器中不存在 Node,因此在启动应用程序之前必须有一个脚本来安装和启动它.所以我有这个 start1.cs 文件:
2) And what I found is Node is not present in the container so it is necessary to have a script to install and start it before starting the app itself. So I have this start1.cs file:
#!/bin/bash
apt-get install curl
curl -sL https://deb.nodesource.com/setup_12.x | bash
apt-get install -y nodejs
set -e
export PORT=8080
export ASPNETCORE_URLS=http://*:$PORT
dotnet "Web.Identity.dll"
Web.Identity.dll 是我的应用程序的 dll.
Where Web.Identity.dll is the dll of my app.
3) 将启动命令设置为 /home/site/wwwroot/start1.sh(在 Azure 门户 - 应用服务配置 - 或 Azure DevOps 上).
3) Set startup command to /home/site/wwwroot/start1.sh (On Azure Portal - App service Configuration - or Azure DevOps).
就是这样.
这篇关于Azure Linux WebApp 上的 ASP.NET Core NodeServices的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!