问题
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.
回答1:
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
To pass parameters into MSBuild you need a .pubxml file (called the publishing profile) within the PublishProfiles folder under your project properties folder.
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" />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>
回答2:
you need a way to deploy the Windows services using MSBuild. Try this Method http://mrchief.calepin.co/deploying-windows-service-via-msbuild/
来源:https://stackoverflow.com/questions/18618467/tfs-msbuild-args-pdeployonbuild-true-doesnt-seem-to-do-anything