Publish Web Deploy using VS Code

AJ Morris picture AJ Morris · May 1, 2015 · Viewed 26.6k times · Source

In Visual Studio, I use the "publish web" feature to do some web.config transforms, and publish a WebAPI project to our server. The publishing is done using Web Deploy.

Now that I'm using Visual Studio Code, I've lost that tooling. But, I'd like to continue publishing the project using Web Deploy. Is there some way to write a VSCode task that will publish my project?

Visual Studio Publish uses a [target].pubxml file. I have "staging.pubxml" and "production.xml". These look like MSBuild files. So, maybe it's just a matter of executing an msbuild task from Code. Not sure where to start with that, though.

Another thought is that I could kick off a Web Deploy command line tool. I've never used that, and it seems like the first idea would be better.

Answer

yuxhuang picture yuxhuang · Nov 29, 2016

Assuming you are using the latest vscode now (1.7.x). You can use Visual Studio Code's Task Runner.

First, you would need to configure the task runner by pressing <F1> and enter task. Select Tasks: Configure Task Runner.

A new file tasks.json would be created by vscode with following content.

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "msbuild",
    "args": [
        // Ask msbuild to generate full paths for file names.
        "/property:GenerateFullPaths=true"
    ],
    "taskSelector": "/t:",
    "showOutput": "silent",
    "tasks": [
        {
            "taskName": "build",
            // Show the output window only if unrecognized errors occur.
            "showOutput": "silent",
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

Second, now you would need to add the new publish task. With the answer given by @Rolo, you can add a new task in the tasks array:

    {
        "taskName": "publish",
        // Always show errors from builds.
        "showOutput": "always",
        "args": [
            "/p:DeployOnBuild=true",
            "/p:PublishProfile=Test"
        ]
    }

Third, once the tasks.json is completed. You can use the publish task by pressing Ctrl+P (or Cmd+P on Mac), and type task publish.