How to deploy project with msdeploy instead of msbuild - msbuild

Today I use msbuild to deploy a web application to an iis server. How can I do the same with msdeploy (command line)?
MSBuild.exe myproject.csproj
/P:VisualStudioVersion=11.0
/P:Password=pass
/P:AllowUntrustedCertificate=true
/P:DeployOnBuild=True
/P:PublishProfile=deploytest
/P:DeployIISAppPath="Default Web site"
/P:MsDeployServiceUrl=my.server.com
/P:Configuration=Release

It depends what you would like your workflow to be, if you want to package the output and deploy that seperately then you'll need to create a zip file from your build.
Create Package
Add the following to your msbuild command line to create a package:
/p:DeployTarget=Package
/p:PackageLocation=MyProject.zip
/p:CreatePackageOnPublish=True
Deploy Package
msdeploy.exe
-verb:sync
-source:Package=MyProject.Zip
-destination:auto:ComputerName="my.server.com"
You might also want to promote from one deployed site to another.
Clone Site
msdeploy.exe
-verb:sync
-source:appHostConfig="my.server.com"
-dest:appHostConfig="mynew.server.com"
Or you may already have a site that you want to target.
Clone Application
msdeploy.exe
-verb:sync
-source:iisApp="my.server.com/MyApp"
-dest:iisApp="my.server.com/MyNewApp"

Related

How do I deploy many MSDeploy publish profiles in a single MSBuild command?

I have a project that I need to deploy with a couple of different configurations (specifically, deploying the same package to 2 different IIS applications). I have set up 2 Publish Profiles, and each creates a package when invoked individually. I'd like to create both packages with a single command.
I've tried commands like this, but they tend to simply ignore the second profile:
msbuild MyWebProject.csproj /p:DeployOnBuild=True "/p:PublishProfile=FirstProfile;PublishProfile=SecondProfile"
Is there a way that I can use a single command to deploy both profiles?
I know this isn't strictly what you are asking for, but have you considered building once and deploying twice?
To achieve this through msbuild, you could create an msbuild project which calls msdeploy.
Build (Create Package)
msbuild MyWebProject.csproj
/p:DeployTarget=Package
/p:PackageLocation=MyWebProject.zip
/p:CreatePackageOnPublish=True
Deploy Package Twice
msdeploy.exe
-verb:sync
-source:Package=MyWebProject.Zip
-destination:auto:ComputerName="my.server1.com"
-declareParamFile:Params1.xml
msdeploy.exe
-verb:sync
-source:Package=MyWebProject.Zip
-destination:auto:ComputerName="my.server2.com"
-declareParamFile:Params2.xml

WebDeploy with MSBuild Not Deploying from TeamCity

I am trying to use MSDeploy to deploy an MVC project to the server using TeamCity. When I do this on my computer in powershell, using the following command:
msbuild.exe .\mvc.csproj /p:PublishProfile=DevServer /p:VisualStudioVersion=11.0
/p:DeployOnBuild=True /p:Password=MyPassword /p:AllowUntrustedCertificate=true
It builds the project and deploys it to the server (info defined in the DevServer publish profile) perfectly. The output shows an MSDeployPublish section at the end, in which I see text like Starting Web deployment task from source... and then with rows telling me what files are updated, etc.
When I run this on TeamCity, using an MSBuild Build step, on the same file, with the same parameters (from the same working directory) it builds the project but does not publish it. Instead it has the regular output from a build process (CoreCompile, _CopyFilesMarkedCopyLocal, GetCopyToOutputDirectoryItems, CopyFilesToOutputDirectory) but then does not actually go and publish anything.
What changes to I need to make to the setup in TeamCity to get it to publish deploy in the same way that it works using MSBuild from my computer?
(TeamCity 7.1, MSBuild 4.0, WebDeploy 3.0, Visual Studio 12, IIS 7. Related to my previous question)
We do our WebDeploys with a TeamCity MSBuild step configured as follows:
Build File Path: Server.csproj
Command Line Parameters:
/p:Configuration=%configuration%
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=https://%web.deploy.server%:8172/MsDeploy.axd
/p:DeployIisAppPath=%web.deploy.site%
/p:AllowUntrustedCertificate=True
/p:Username=
/p:AuthType=NTLM
We use integrated authentication; change as necessary to fit your scheme. The value of this, I think, is that it builds everything from scratch and doesn't rely on a pre-built package. From the gist you posted I noticed that you do some DB publishing, we don't use WebDeploy for that so I can't offer any guidance there. Hope this helps.
I use MSBuild.exe to package to zip, and MSdeploy.exe to deploy in separate steps.
To deploy the package.zip file on the command line:
"C:\Program Files\IIS\Microsoft Web Deploy V2\msdeploy.exe" -verb:sync
-source:package="C:\Build\MyAppName.Debug.zip"
-dest:auto,wmsvc=webservername,username=webdeploy,password=*******
-allowUntrusted=true
This command is also worth explaining in detail:
-verb:sync : makes the web site sync from the source to the destination
-source:package="C:\Build\MyAppName.Debug.zip" : source is an MSBuild zip file package
-dest:auto,wmsvc=webservername : use the settings in the package file to deploy to the server. The user account is an OS-level account with permission. The hostname is specified, but not the IIS web site name (which is previously specified in the MSBuild project file in the project properties).
You can modify parameters based on your configuration. I like it this way because with separate steps, its easier to debug problems.
Use TeamCity build step and the command line runner.
Update:
If you want an example of how to build the ZIP package using MSBuild, try something like this:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
MyWebApp/MyWebApp/MyWebApp.csproj
/T:Package
/P:Configuration=Debug;PackageLocation="C:\Build\MyWebApp.Debug.zip"
This should work the same on your local PC as well as on the CI server.
Here are the config settings that finally worked for me:
/p:Configuration=CONFIG-NAME
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=http://SITE-URL/MsDeployAgentService
/p:username="USERNAME"
/p:password=PASSWORD
/p:AllowUntrustedCertificate=True
/P:CreatePackageOnPublish=True
/p:DeployIisAppPath=SITE-URL
/p:MSDeployPublishMethod=RemoteAgent
/p:IgnoreDeployManagedRuntimeVersion=True
I had exactly the same issue! I've posted the solution I used over at: MsBuild not finding publish profile
Basics were:
Install the Azure SDK 1.8 on the build server
Force the /P:PublishProfileRootFolder value to ensure MSBuild can locate the publish profile
Ensure that you have the Microsoft Web Developer Tools feature installed for Visual Studio. This was missing on my build agent but once I added it the TeamCity build worked just fine.
This can happen when the build target paths are missing from your MSBuild directory. Instead of trying to get those to line up on every developer machine, install the targets from the Nuget. That way it will always be the same for everyone, regardless of how their machine is setup.

MsBuild and MsDeploy problems

When I publish web project by gui(VS2010) (right click in project and choose Publish menu item, publish Method - Web Deploy) - everything works fine.
Problems appear when I am trying to publish via command line: MSBUILD or MsDeploy.
With MSBuild a package is created with no publishing (only creating package):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSbuild.exe" Project.sln /p:DeployOnBuild=true /p:DeployTraget=MSDeployPublish /p:MSDeployPublishMethod=WMSVC /p:MSDeployServiceUrl=https://[ip]/msdeploy.axd /p:AllowUntrustedCertificate=true /p:DeployIisAppPath=NlbTestSite /p:UserName=M\DeployUser /p:Password=qwerty
With MsDeploy i get an error: ERROR_USER_UNAUTHORIZED
E:\Work\OutDir\MSDeploy\Package.deploy.cmd" /Y /M:"https://[ip]:8172/msdeploy.axd" /U:"M\DeployUser" /P:"qwerty" -allowUntrusted /A:Basic
My goal is to automate the deployment process using one of those methods.
I want to find out how Visual Studio publishes my project (what command with what arguments)?
UPDATE 19.10.2012 14:52
When I add /p:UseMsDeployExe=true, msdeploy.exe is executed, but nothing is copied.
The execution command:
C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe -source:manifest='E:\[Path]\obj\Debug\Package\[Project].SourceManifest.xml' -dest:package='E:\[Path]\[Project]\obj\Debug\Package\[Project].zip',IncludeAcls='False' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -declareParam:name='IIS Web Application Name',kind='ProviderPath',scope='IisApp',match='^E:\\[Path]\\obj\\Debug\\Package\\PackageTmp$',defaultvalue='[SiteName]',tags='IisApp' -declareParam:name='IIS Web Application Name',kind='ProviderPath',scope='setAcl',match='^E:\\[Path]\\obj\\Debug\\Package\\PackageTmp$' -declareParam:name='Add write permission to App_Data Folder',kind='ProviderPath',scope='setAcl',match='^E:\\[Path]\\obj\\Debug\\Package\\PackageTmp\\App_Data$',description='Add write permission to App_Data folder',defaultvalue='{IIS Web Application Name}/App_Data',tags='Hidden' -declareParam:name='MainModelContainer-Web.config Connection String',kind='XmlFile',scope='E:\\[Path]\\OutDir\\temp\\Web\.config$',match="/configuration/connectionStrings/add[#name='MainModelContainer']/#connectionString",description='MainModelContainer Connection String used in web.config by the application to access the database.',defaultvalue='metadata=[ConnectionString]"',tags='SqlConnectionString' -declareParam:name='SimpleConnection-Web.config Connection String',kind='XmlFile',scope='E:\\[Path]\\OutDir\\temp\\Web\.config$',match="/configuration/connectionStrings/add[#name='SimpleConnection']/#connectionString",description='SimpleConnection Connection String used in web.config by the application to access the database.',defaultvalue='[ConnectionString]',tags='SqlConnectionString' -declareParam:name='ElmahDB-Web.config Connection String',kind='XmlFile',scope='E:\\[Path]\\OutDir\\temp\\Web\.config$',match="/configuration/connectionStrings/add[#name='ElmahDB']/#connectionString",description='ElmahDB Connection String used in web.config by the application to access the database.',defaultvalue='[ConnectionString]',tags='SqlConnectionString' -retryAttempts=2
No parameters, such as ComputerName, User or password are passed.
Any ideas about the cause?
Problem solved.
Got some ideas from http://root-project.org/work/net/automated-web-deployment-with-msbuild-and-msdeploy
I separated msbuild and msdeploy, and executed msdeploy explicitly.
Here is the template:
msdeploy.exe
-source:package=’C:\SomeWebProject\obj\Release\Package\SomeWebProject.zip‘
-dest:auto,ComputerName=’https://TargetServer:8172/MsDeploy.axd?site=TargetWebSite‘,UserName=’Username‘,Password=’Password‘,IncludeAcls=’False’,AuthType=’Basic’
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-allowUntrusted
-retryAttempts=2
-setParam:’IIS Web Application Name’=’TargetWebSite/TargetWebApp‘
But problem with msbuild still remains.
In your pubxml file, declare the following:
<PropertyGroup>
<UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>
Now when you deploy, you should see the call to msdeploy.exe in the publih log.
Make note, though, that it will actually be calling msdeploy.exe directly, and not via the generated deploy.cmd file.

Specifying project name in msdeploy

I've got two web projects in one solution, and I'd like to deploy them both using msbuild and WebDeploy (this happens through a CI server).
Currently, I'm running a command line:
C:\ProjectFolder>msbuild <solution>.sln
/p:Configuration=<Release>
/p:OutputPath=bin
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=https://<ServerUrl:port>/msdeploy.axd
/p:username=<user>
/p:password=<password>
/p:AllowUntrustedCertificate=True
/p:DeployIisAppPath=<SiteName>
/p:MSDeployPublishMethod=WMSVC
This deploys one project, as expected. But how can I deploy the other as well? There's nowhere in this command line where I specified a project name - why did it choose one project to deploy over the other?
Ideally, I'd be able to deploy two project with the same command, something like
...
/p:Project=Project1
/p:DeployIisAppPath=<SiteName>/Project1
/p:Project=Project2
/p:DeployIisAppPath=<SiteName>/Project2
But I doubt that's possible. Alternatively, I just want to know how to specify a project name in the command line.
I think it would be better to divide the single call to three:
- Build sln;
- Deploy site1;
- Deploy site2;
msbuild.exe <solution>.sln
/p:Configuration=<Release>
/p:OutputPath=bin
msbuild.exe project1dir\proj1.csproj
/p:Configuration=<Release>
/p:OutputPath=<Path to common bin>
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=https://<ServerUrl:port>/msdeploy.axd
/p:username=<user>
/p:password=<password>
/p:AllowUntrustedCertificate=True
/p:DeployIisAppPath=<SiteName>/Project1
/p:MSDeployPublishMethod=WMSVC
msbuild.exe project1dir\proj2.csproj
/p:Configuration=<Release>
/p:OutputPath=<Path to common bin>
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=https://<ServerUrl:port>/msdeploy.axd
/p:username=<user>
/p:password=<password>
/p:AllowUntrustedCertificate=True
/p:DeployIisAppPath=<SiteName>/Project2
/p:MSDeployPublishMethod=WMSVC
If you run the command line from the projects' root folder(s), and don't specify a file to build, msbuild should automatically select the project in that folder.
This will require two separate command line calls, tho.
You can then build on this by building a batch file that cd's to each of the folders in turn and runs msbuild separately, or equally build your own proj file for msbuild that triggers each build.
Sorry I can't craft an example at the moment tho-on a phone!

MSBuild 4 and MSDeploy command line

I'm trying to automate deployment of a site. I started with this article
and everything works great from VS 2010. However, I'm having problems with the command line
I use this
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe "d:\Projects\test.csproj" /T:Package /P:PackageLocation="d:\Package\packageTest.zip"
to create the package
and
d:\Projects\packageTest.deploy.cmd "-setParam:name='IIS Web Application Name',value=MSBuild/Test2" /y
to get to at least deploy correctly.
However, it doesn't take any of the IIS options (the app pool is MSBuild instead of ASP.NET v2.0) and, as I said before, the IIS Web Application Name is wrong.
Shouldn't this information be taken from .csproj file?
All these settings are done for debug configuration and platform any cpu
You typically setup your application on the IIS first, with correct path, application pool and so forth. When setup you can use MSBuild to deploy into that application name like this:
msbuild <your_web_project_name>.csproj /p:Configuration=Release /p:OutputPath=bin /p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MsDeployServiceUrl=https://<url_to_your_server>:8080/msdeploy.axd /p:username=<username> /p:password=<password> /p:AllowUntrustedCertificate=True /p:DeployIisAppPath=<your_site_name> /p:MSDeployPublishMethod=WMSVC /p:VisualStudioVersion=11.0
If you don't want to setup the site manually, you could run a power shell looking something like this:
Import-Module WebAdministration
New-Item iis:\Sites\<your_site_name> -bindings #{protocol="http";bindingInformation=":80:<your_site_name>} -physicalPath c:\inetpub\wwwroot\<your_site_name>
Set-ItemProperty 'IIS:\Sites\<your_site_name>' ApplicationPool "ASP.NET v4.0"