Sunday, 18 November 2012

tfs msbuild MVC3

You know the time spent, when you do change on a web project and want clients to see what you have done?  I have timed one of my releases, with build, publish. It can easily take me up to half an hour, for a bigger project. I have known for a while that you can publish it from TFS build process. So everytime you commit your change into TFS server, you can have automated build triggered and this can do deployment. The company that I work for is doing just this with a website webforms.

I do not like to copy anyones work, and found out about this process myself and wanted to save myself time when releasing when tfs build succeds.

Step one:

Open visual studio command line:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat""

Now you can run msbuild command.

Step two:
Create your publish.msbuild file.

Step three:

File content
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"  xmlns="">
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

 <Target Name="Build" >
    <Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." />
    <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" />
    <MSBuild Projects="WebUi\WebUi.csproj"
    DeployOnBuild=true;    DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;_PackageTempDir=$(PublishDestination);" />