Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS msbuild args /p:DeployOnBuild=true doesn't seem to do anything

I'm currently using TFS and the regular build process activity to build a solution. However, I'd like to be able to automate deployment so I can build and deploy remotely to a server in one step.

On the MSBuild arguments I am trying to specify the deployment switch. My project is a windows service, but I understand it is still possible to deploy any binaries regardless of the project type (not being a web project).

Current build parameters:

/p:DeployOnBuild=True /p:UserName=user /p:Password=password

When the build runs in TFS it succeeds, however I was expecting to see some attempt at deployment to the server and some helpful error message but nothing shows.

like image 360
jaffa Avatar asked Sep 04 '13 15:09

jaffa


1 Answers

For future reference, I've found exactly what is required to enable deployments for anything other than web services/projects. The reason the DeployOnBuild parameter doesn't do anything for anything other than web projects is that the project file needs to include the webapplication.targets and also a PropertyGroup containing the path to the VSToolsPath.

This link here gave me a good introduction as to how web deployments work and how to integrate this into my project to deploy services:

http://www.asp.net/web-forms/tutorials/deployment/web-deployment-in-the-enterprise/building-and-packaging-web-application-projects

  1. To pass parameters into MSBuild you need a .pubxml file (called the publishing profile) within the PublishProfiles folder under your project properties folder.

  2. I needed the following in the .csproj file:

    <PropertyGroup>
        <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
        <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
      </PropertyGroup>
    
      <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
      <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
      <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
    
  3. If you need the pre-sync/post-sync commands of MSDeploy, unfortunately this is not available from MSBuild. To do achieve this functionality you need to have a X.Wpp.Targets (where X is your project name) inside your project root folder.

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Target Name="UninstallService" BeforeTargets="MSDeployPublish">    
          <!-- Do exec tasks here -->
      </Target>
    
      <Target Name="InstallService" AfterTargets="MSDeployPublish">    
          <!-- Do exec tasks here -->            
      </Target>
    </Project>
    
like image 109
jaffa Avatar answered Nov 15 '22 17:11

jaffa