让 VS2019 使用 Yarn 而不是 NPM

Make VS2019 use Yarn instead of NPM

当我启动 运行ning 我的 ASP.Net Core/React webapp 时,它使用 NPM 下载包。我希望它改用 Yarn。

我可以从命令行使用 Yarn,它可以很好地恢复包。 我还安装了 this 扩展,效果很好,使用 Yarn 恢复包,但只有当我对 package.json.

进行更改时

我需要的是一种在我第一次检查代码并点击 Visual studio 中的绿色 'Run' 按钮时使用 Yarn 的方法,它会尝试 运行 它,意识到缺少 node_modules,然后尝试下载包。

我认为可能是在 package.json

的脚本部分添加了这种东西
"start": "yarn react-scripts start",
"build": "yarn react-scripts build",

但到目前为止它总是使用 NPM。

背景:在升级一些包以修复一些其他问题的过程中,NPM 弄得一团糟,而 Yarn 做得很好。

谢谢

答案就在CSPROJ 文件中。我不熟悉用 npm 正确交换 yarn,但这就是 VS 能够构建和发布 dotnet + react/angular/vue 项目的方式。

如果你做一个文件 -> 新的 ReactJs 应用程序,你可以很容易地剖析 CSPROJ。

例如;这里VS是hook到BeforeTargets="Build",所以工程建好后,可以执行npm install.

<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
    ...
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>