Specifying project name in msdeploy - msbuild

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!

Related

MSBuild arguments to generate files

notes:
Visual Studio 2017 solution with an MVC web app and several other projects, not all of which are referenced by the web app project. Until now Ive been using VS directly to publish to a test server, but I have moved things into VSTS and have a build & release definition setup but not working yet.
What im trying to achieve, is to get my (hosted) VSTS build agent to produce the published files that my (on-prem) release agent can simply copy to its target destination. So, Im trying to test the MS build step locally from the VS command line so as to get the files produced and note the path they are at. Maybe Im making this more complicated that it needs to be?
These options will create a single zipped archive and its associated files and place it into the artefact staging dir. Is there a way to simply publish the files WITHOUT putting them in an archive - and directly into the artefact staging dir?
Visual Studio Build
MSBuild parameters
/t:My_MVCWeb_Project_Name /p:DeployOnBuild=true
/p:WebPublishMethod=FileSystem /p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\\"
In my release using on-prem agent),
I have a "copy files" task, with the destination as the unc path where the IIS app is located. However, that will just copy over the archive. So how can I just copy the files as if I was using a publish profile, straight to the app directory?
[update2 - still getting zip file produced ]
MSBuild my_solution_name /t:"my_project_name" /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:PackageLocation="D:\temp\local-dev-build-dir"
[ update 3 ]
Trying these from the command line as a test, but nothing is generated
msbuild D:\app_dir>MSBuild my_solution_name.sln /t:"my_web_proj_name" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="D:\temp\app_build_dir\\"
/p:DeployDefaultTarget=WebPublish
Using these MSBuild Arguments instead:
/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish
Remove the
/p:PackageAsSingleFile=true
Or change it to:
/p:PackageAsSingleFile=false
That is causing the files to be zipped up.
You may also need to switch the publishing method to package:
/p:OutDir=$(build.artifactstagingdirectory)
/p:WebPublishMethod=Package

Publishing and packaging code with MSBuild.exe

Hi I need to publish my code using MSbuild.exe and create a package of the publish code to a location.
Need to understand how target file will work and the arguments I need to pass while calling the MSbuild.exe
If you are looking to keep code in a folder the better way to do it is to package it since your intentions are to deploy it to IIS later. That way the deployment will process will be easier and clean.
Below is the command to create and save package to desired location:
msbuild "Your\Solution\location\YourSolution.sln" /t:build /P:configuration="Debug-Dev" /p:platform="Any CPU" /p:VisualStudioVersion=14.0 /p:DeployOnBuild=True /p:CreatePackageOnPublish=True /p:DeployOnBuild=True /p:DeployTarget=Package /p:PackageLocation="\wherever\you\want"

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

How to deploy project with msdeploy instead of 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"

Parsing argument to MSDeploy from MSBuild

I have just started playing with TeamCity and its great. Now I got it to deploy to my staging server after a commit so I always know I have the latest version running there. ( The idea was borrowed from: http://www.agileatwork.com/automatic-deployment-from-teamcity-using-webdeploy/ )
But as the site generates some files which I dont want to wipe out on every publish I found the parameter to MSDeploy
-enableRule:DoNotDeleteRule
But how do I append this to MSBuild command
MSBuild.exe MvcApplication1.sln
/p:Configuration=Debug
/p:OutputPath=bin
/p:DeployOnBuild=True
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=https://ss-iis:8172/MSDeploy.axd
/p:username=user
/p:password=pass
/p:AllowUntrustedCertificate=True
/p:DeployIisAppPath=foo.bar.tld
/p:MSDeployPublishMethod=WMSVC
Can this be done?
Or is there are a more fancy way of doing automatic web deployments from TeamCity?
It might be /p:SkipExtraFilesOnServer=true that you want.