ASP.NET Core 找不到 npm指令异常
发布时间:2020-12-16 07:18:01 所属栏目:asp.Net 来源:网络整理
导读:1.错误再现 利用VS2019预览版创建ASP.NET Core 的单页面Web程序 创建后直接运行,出现如下错误 ?Ensure that ‘npm‘ is installed and can be found in one of the PATH directories. ? 2.相关资料 找到以下资料 https://github.com/aspnet/AspNetCore/issu
1.错误再现 利用VS2019预览版创建ASP.NET Core 的单页面Web程序 创建后直接运行,出现如下错误 ?Ensure that ‘npm‘ is installed and can be found in one of the PATH directories. ? 2.相关资料 找到以下资料 https://github.com/aspnet/AspNetCore/issues/5263 https://github.com/aspnet/AspNetCore.Docs/blob/master/aspnetcore/host-and-deploy/aspnet-core-module/samples_snapshot/2.x/CurrentDirectoryHelpers.cs ? 3.解决方案 添加类CurrentDirectoryHelpers,代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace WebApplication6 { public class CurrentDirectoryHelpers { internal const string AspNetCoreModuleDll = "aspnetcorev2_inprocess.dll"; [System.Runtime.InteropServices.DllImport("kernel32.dll")] private static extern IntPtr GetModuleHandle(string lpModuleName); [System.Runtime.InteropServices.DllImport(AspNetCoreModuleDll)] private static extern int http_get_application_properties(ref IISConfigurationData iiConfigData); [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)] private struct IISConfigurationData { public IntPtr pNativeApplication; [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)] public string pwzFullApplicationPath; [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)] public string pwzVirtualApplicationPath; public bool fWindowsAuthEnabled; public bool fBasicAuthEnabled; public bool fAnonymousAuthEnable; } public static void SetCurrentDirectory() { try { // Check if physical path was provided by ANCM var sitePhysicalPath = Environment.GetEnvironmentVariable("ASPNETCORE_IIS_PHYSICAL_PATH"); if (string.IsNullOrEmpty(sitePhysicalPath)) { // Skip if not running ANCM InProcess if (GetModuleHandle(AspNetCoreModuleDll) == IntPtr.Zero) { return; } IISConfigurationData configurationData = default(IISConfigurationData); if (http_get_application_properties(ref configurationData) != 0) { return; } sitePhysicalPath = configurationData.pwzFullApplicationPath; } Environment.CurrentDirectory = sitePhysicalPath; } catch { // ignore } } } } 在Main方法中调用 运行,发现神奇般的好啦!!! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .net中基于资源的授权
- asp.net-mvc – 为什么我的IIS Express Web应用程序项目在尝
- asp.net mvc框架,自动发送电子邮件
- asp.net – 动态设置超链接控件的navigationurl属性内联
- asp.net-mvc-3 – 实体框架4.1自动日期
- iis-7 – 经典asp:错误’800a01ad’ActiveX组件无法创建对
- 每个“HttpRequest”在ASP.NET中都有自己的线程吗?
- asp.net核心 – 为什么验证类型 – .NET Core中的Web API的
- ASP.NET JSON Web令牌“401 Unauthorized”
- asp.net – Facebook评论审核困难
推荐文章
站长推荐
- asp.net-core – .NET核心托管包
- 不同的asp.net Web服务和Ihttphandler
- asp.net – 从ActionFilterAttribute返回自定义H
- asp.net-mvc-3 – 另一个数据库实例RavenDB MVC3
- asp:Repeater 添加button 事件
- asp.net核心 – 在ASP.NET核心应用程序中使用NLo
- asp.net signalR 专题—— 第四篇 模拟RPC模式的
- asp.net-mvc – 独立开发/部署MVC区域
- asp.net – 更改User-Agent标头触发表单身份验证
- asp.net-mvc – 在mvc 4上获取当前文化或浏览器区
热点阅读