本文介绍了带有 .Net Core Stack 的 Azure Linux 应用服务.无法使用 NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MS Azure 上托管一个 .NET Core 应用程序(基于 Linux 服务计划),我想在 .NET Core 应用程序中运行一些 NodeJS 代码.不久前我在 Windows 服务计划中这样做了,它正在工作.现在我正在尝试使用 Linux 计划,但它不起作用.

I am hosting a .NET Core Application on MS Azure (on a Linux Service Plan) and I want to run some NodeJS code in the .NET Core Application. I did this a while ago on a Windows Service Plan, there it was working. Now I am trying with a Linux Plan and it is not working.

首先我尝试使用Jering.Javascript.NodeJS";然后还有INodeServices"来自 Microsoft(已过时).但是节点"没有找到.我也尝试直接启动一个进程(下面的代码),但也没有工作.节点"未找到.

First I was trying to use "Jering.Javascript.NodeJS" and then also "INodeServices" from Microsoft (which is obsolete). But "node" was not found. I also tried to start directly a Process (Code below), but also not working. "node" is not found.

            var proc = new System.Diagnostics.Process
            {
                StartInfo = new System.Diagnostics.ProcessStartInfo
                {
                    FileName = "node",
                    Arguments = " -v",
                    RedirectStandardOutput = true
                }
            };
            result += "RUN: " + proc.StartInfo.FileName;
            proc.Start();
            var reader = proc.StandardOutput;

NodeJS 安装在服务器上,命令也在那里工作,但似乎 .NET Core 应用程序作为 docker 托管并且没有任何外部访问权限来运行 NodeJS.图片

NodeJS is installed on the server and also the command works there but it seems that the .NET Core app is hosted as docker and does not have any access outside to run NodeJS. Image

推荐答案

我想我找到了更好的解决方案 ;)在应用服务中,您可以挂载存储.就我而言,我安装了一个存储,其中包含 nodeJS 库.Azure 门户屏幕截图

I think I found a better solution ;)In an app service you can mount a storage. In my case I mounted a storage, which contains the nodeJS lib.Azure Portal Screenshot

现在我可以执行以下代码:

Now i can execute the following code:

string result = "";
var proc = new System.Diagnostics.Process
{
    StartInfo = new System.Diagnostics.ProcessStartInfo
    {
        FileName = "/externallibs/node/bin/node",
        Arguments = " -v",
        RedirectStandardOutput = true
    }
};
result += "RUN: " + proc.StartInfo.FileName;
proc.Start();
var reader = proc.StandardOutput;
return result +  reader.ReadToEnd();

这篇关于带有 .Net Core Stack 的 Azure Linux 应用服务.无法使用 NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 06:08