MSBuild 在 Rider/Visual Studio 中编译项目时无法执行命令 'npm i'



我需要使用Visual Studio for Mac或Jetbrains Rider在Mac中构建和运行。net 5项目。

在解决方案中一个项目的csproj文件中,我有以下目标:

<Target Name="SassBuild" BeforeTargets="Build" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Exec Command="npm i" />
<Exec Command="npm rebuild node-sass" />
<Exec Command="npm run gulp-sass" />
<Exec Command="npm run gulp-js" />
</Target>

当我运行dotnet builddotnet msbuild项目构建很好,但是在VS/Rider中构建它会抛出以下错误:

Error MSB3073: The command "npm i" exited with code 127. (MSB3073)

日志中的详细信息:

Target SassBuild:
npm i
/var/folders/9l/d02_tk1j5f93vklft82p1z996dm09b/T/tmp89785a0aeebb4347a3696de11d8c281e.exec.cmd: line 2: npm: command not found
PATH_TO_CSPROJ_HERE.csproj(232,5): error MSB3073: The command "npm i" exited with code 127.
Done building target "SassBuild" in project "X.csproj" -- FAILED.

npm已经安装,我可以在终端运行npm命令。我使用nvm进行节点版本控制。

任何想法?

好吧,我发现Mac OS终端和VS/Rider终端不是来自同一个终端配置文件;这就是为什么ide无法在它们的路径中找到npm。

我将所有nvm相关配置从~/.zprofile复制到~/.profile,现在我能够在VS/Rider中构建项目。

希望它能帮助到有同样问题的人。

最新更新