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

问题描述

我正在Linux计划上在MS Azure上托管.NET Core应用程序,并且我想在.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