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.
Open your web application with Visual Studio 2015, right click the web application, then click"Publish" to start. 3. You can download Publish XML at your control panel,then Import it,you can also use Custom settings.
Create or open an Azure cloud service project in Visual Studio. In Solution Explorer, right-click the project, and, from the context menu, select Convert > Convert to Azure Cloud Service Project. In Solution Explorer, right-click the newly created Azure project, and, from the context menu, select Publish.
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
.
In order to publish using MSBuild you need to use the following command:
msbuild <Project or Solution Path> /p:DeployOnBuild=true /p:PublishProfile=<Publish Profile Name>
You can point to a solution, this will publish ALL the projects that includes a valid Publish Profile:
msbuild <FullPath>\MySolution.sln /p:DeployOnBuild=true /p:PublishProfile=Test
You can point to a specific project like this:
msbuild <FullPath>\Project1\MyProj.csproj /p:DeployOnBuild=true /p:PublishProfile=Test
In both cases you can also specify use the full path to the .pubxml file:
msbuild <FullPath>\MySolution.sln /p:DeployOnBuild=true /p:PublishProfile=<FullPath>\PublishProfiles\Test.pubxml
In fact the *.pubxml files are MSBuild scripts, so you can interact with it like you do with any other MSBuild script, for example you can replace the properties from the command line like this:
Test.pubxml
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Deploy\MyProject\</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
msbuild <FullPath>\MySolution.sln /p:DeployOnBuild=true /p:PublishProfile=<FullPath>\PublishProfiles\Test.pubxml /p:publishUrl:"D:\DifferentPath\DifferentFolder\"
You can use these commands from your continuous integration server or any other build scripts.
Additional information:
Command Line Deployment
Visual Studio Code does not have an integrated build system (Web Publish) like Visual Studio does. But it does have command line task running and Git built in.
So you have a couple of options:
1) Use a task runner to kick off your build/publish from the command palette (ctrl+p). Grunt is available in the preview*. This requires that you manually script it out, but once that is done, it is easy to kick off the task from that point.
(UPDATE: the docs mention other compatible task runners including: Make, Ant, Gulp, Jake, Rake or MSBuild -- AND the .settings tasks.json has examples of how to get your MSBuild files working. Press ctrl+p type: "run task" and then click "configure tasks")
2) Setup your source control system for continuous integration so that when you push an update to a specific branch, it will run the MSBuild (or other build system) scripts and publish to the server for you. We use Team Foundation Server (TFS) and Git. We have a specific "release/master" branch that is setup to build and publish when it receives a push. It also takes some initial configuration, but once complete, it is automatic. If you don't have TFS, try TFS online. There are many other options out there, but that's what we use.
I am in the same position as you trying to figure this one out. I would love to know what you find out.
*According to the Deep Dive session at Build 2015. Although looking at the tasks.json file it looks like Gulp and MSBuild examples are available in the Preview.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With