簡體   English   中英

在 Rider/Visual Studio 中編譯項目時,MSBuild 無法執行命令“npm i”

[英]MSBuild can't exec command `npm i` while compiling a project in Rider/Visual Studio

我需要使用 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 "TicToc.T3.Web.csproj" -- FAILED.

npm已經安裝,我可以在終端中運行 npm 命令。 我使用nvm進行節點版本控制。

有任何想法嗎?

好吧,我發現 Mac OS 終端和 VS/Rider 終端不是來自相同的終端配置文件; 這就是 IDE 無法在其路徑中找到 npm 的原因。

我將所有與nvm相關的配置從~/.zprofile~/.profile ,現在我可以在 VS/Rider 中構建項目。

希望它能幫助任何遇到同樣問題的人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM