在Visual Studio代码上运行两个命令

时间:2016-11-28 22:51:54

标签: asp.net-core visual-studio-code

我正在使用Visual Code 1.7和ASP.NET Core 1.1,我有以下launch.json:

{
 "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Launch (Web)",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/bin/Debug/netcoreapp1.1/MVC.dll",
      "args": [],
      "cwd": "${workspaceRoot}",
      "stopAtEntry": false,
      "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
          "command": "cmd.exe",
          "args": "/C start ${auto-detect-url}"
        },
        "osx": {
          "command": "open"
        },
        "linux": {
          "command": "xdg-open"
        }
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceRoot}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command.pickProcess}"
    }
  ]
}

这是有效的,但我还需要在启动时运行两个gulp任务:

gulp clearCssJs
gulp buildCssJs

我有以下tasks.json:

  {
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
    {
      "taskName": "build",
      "args": [ ],
      "isBuildCommand": true,
      "showOutput": "silent",
      "problemMatcher": "$msCompile"
    }
  ]
}    

所以我需要在tasks.json和dotnet构建任务中有2个gulp任务。

我错了吗?我怎么能这样做?

更新

为了澄清,我的csproj上已经有以下内容:

<Target Name="Prepublish" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
  <Exec Command="npm install" />
  <Exec Command="bower install" /> 
  <Exec Command="gulp clean" />
  <Exec Command="gulp build" />
</Target>  

<Target Name="PostpublishScript" AfterTargets="Publish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
  <Exec Command="dotnet publish-iis --publish-folder $(TargetDir) --framework $(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)" />
</Target>   

因此,这允许在发布到服务器时运行npm,bower和gulp任务...

关键是当我在我的开发机器上运行并进行调试时...我认为仅启动Gulp任务并使用Visual Studio Code并且不将它们放在项目文件中更合适。否?

1 个答案:

答案 0 :(得分:0)

您需要研究的是project.json。它有一个scripts部分,可以定义一组需要在编译,发布之前/之后运行的脚本。例如:

{ "scripts": { "precompile": [ "gulp clearCssJs" ], "postcompile": [ "gulp buildCssJs" ] } }

我自己没有试过,但我相信它会奏效。