ASP.NET Core 找不到 npm指令异常
2024-09-06 05:18:52
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
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方法中调用
运行,发现神奇般的好啦!!!
转载于:https://www.cnblogs.com/zhangqibao/p/10839226.html
最新文章
- MySql事务概述
- Floyd算法(一)之 C语言详解
- android AsyncTask介绍(转)
- poj 1114 完全背包 dp
- 目前主流的国产WebApp框架
- ui学习笔记---第十五天数据库
- linux下的chmod,chown和chgrp
- Flexible 弹性盒子模型之CSS flex-direction
- DelphiXE4- System.IOUtils.TDirectory笔记查询后缀名为dll的文件
- QLGame 2d Engine源码地址
- EDM(邮件营销)
- 共享内存操作类(C#源码)
- Linux分配给该用户没有权限登陆
- Grunt实现自动化单元测试
- 团队作业4——第一次项目冲刺(Alpha版本)2017.4.27
- ubuntu 14.04 vim YoucompleteMe 代码自动补全工具安装
- [转]SVN使用log,list,cat,diff查看所有及特定文件版本信息
- codeforces#1136E. Nastya Hasn't Written a Legend(二分+线段树)
- fastclick的介绍和使用
- 自学Linux Shell9.2-基于Red Hat系统工具包存在两种方式之一:RPM包
热门文章
- PTA | 1014 福尔摩斯的约会 (20分)
- PTA | 1005 继续(3n+1)猜想 (25分)
- Jmeter 压力测试笔记(3)--脚本调试/签名/cookie/提升吞吐量/降低异常率/提升单机并发性能
- 通过operator函数将字符串转换回运算符
- 数据科学 R语言速成
- PowerShell入门简介
- NullPointerException的处理新方式,Java14真的太香了
- Boyer-Moore字符串搜索(BM算法)的Python实现
- Python设计模式(10)-模板模式
- hadoop(十一)HDFS简介和常用命令介绍