reactjs - 没有找到任务运行器配置?

标签 reactjs visual-studio npm webpack

我有(新安装的)Visual Studio Professional 2017 (V 15.9.4),一个 Visual Studio solution对于多个项目,单个 .sln 文件和项目的 package.jsons 在各自的项目文件夹 exampleCoorp.APIexampleCoorp.UI等。前端项目用React编写,其他项目用C#编写。

当我导航到 View > Other Windows > Task Runner Explorer(最初由 Mads Kristens 下放,参见 marketplace.visualstudio.com)。因为我们也有 React 部分,所以我有扩展名 NPM Task Runner也安装好了。

我预计会出现以下情况(来 self 的队友的屏幕截图,我遵循了他们的项目设置说明):

TaskRunnerExplorer expected result

但是,对我来说实际结果看起来不同:

TaskRunnerExplorer actual result

我必须理解的错误来自显示的 Visual Studio 面板:

No task runner configurations are found.

但是为什么呢?更重要的是,我该如何解决?有解决方法吗?

只有一个 google-hit [ developercommunity.visualstudio.com ] 声称(唯一?)原因可能是放错位置的 package.json 文件:

Both problems are caused by the fact that Visual Studio’s NPM integration does not support a package.json file that is in a subfolder instead of the project root. Microsoft’s own official Angular project template requires that the package.json be placed in the /ClientApp subfolder, which is not something that is going to change.

这显然不是我的问题。任何帮助提示表示赞赏!

最佳答案

NPM Task Runner 扩展只会查找 Visual Studio 项目文件夹 包含“package.json”文件的任务。如果此文件位于子文件夹(或父文件夹,即使您认为这是主“项目”文件夹),您将不会在 Task Runner Explorer 中看到这些任务。

提问者使用“项目”一词来表示两种不同的事物。他说他有一个“带有多个子项目的 React 项目”。 “Visual Studio 项目”不能有“子项目”,所以我想知道 package.json 文件到底在哪里。 [他随后改变了措辞,但我认为这可能是最有可能出现问题的原因。]

如果您在 VS 项目文件夹之一中创建 package.json 文件,您将立即看到 TR Explorer 将该项目添加到其下拉列表中,您可以选择在 TR Explorer 中查看其任务。您不需要重新启动 VS,甚至不需要重新构建。

SPA 模板创建了一些项目,将客户端代码放在项目文件夹的子文件夹中。例如,“dotnet new angular”将客户端代码及其 package.json 文件放在子文件夹“ClientApp”中。在这种情况下,如果您想从 TR Explorer 访问这些任务,您需要执行以下操作: 在 VS 项目文件夹中创建一个 package.json 文件,该文件将代理您要使用的那些。例如:

{
  "scripts": {
    "serve": "cd ClientApp && npm run serve",
    "build": "cd ClientApp && npm run build"
  },
  "-vs-binding": {
    "BeforeBuild": [
      "build"
    ]
  }
}

关于reactjs - 没有找到任务运行器配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57429114/

相关文章:

javascript - React-Select 自定义选项数组?

c# - 如何调试 MSBuild 依赖问题?

javascript - 如何在 React JS 中执行基于条件的不重复自己(干)原则?

VB.NET Lambda 表达式

c# - 如何在 Windows 10 中运行 Visual Studio 创建的 C# exe 文件?

npm - SemVer 冲突 : How to release bug fix over the last stable version if there are some alpha/beta/rc versions and the work is in progress?

node.js - 全局安装的node-dev导致错误 "command not found"

javascript - 将 Node.js 数据传递给 React

javascript - 使用 sortBy redux 操作对 redux 存储数组进行排序不会向组件发送新的 props

javascript - 差异,当可观察变量在 mobx 中的 Action 方法和普通函数内更新时?