Click here to Skip to main content
15,880,796 members
Articles / Hosted Services / Azure

Simple Deploy to Azure from Command Line

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
1 Sep 2017CPOL1 min read 4.5K   3  
Simple deploy to Azure from Command line

I’m currently working on moving our product from AWS to Azure and as part of the planning for that move, one of the problems I needed to solve was deployment. Our current deployments are handled by an automated build on Bamboo, but Bamboo doesn’t have a “Deploy to Azure” task. I needed to do the deploy from the command line (CMD or Powershell), and I wanted to avoid including publish profiles in the projects.

The first part, running from the command line was easy to find through with a Google search. You can just tell MSBuild to publish to Azure:

msbuild MyWeb\MyWeb.csproj /t:TransformWebConfig;Publish 
/p:TargetProfile=ProdMyWebApp /p:Configuration=AzDev

But the catch is that you can’t do it without a publish profile as part of your project or at least I wasn’t able to make it work.

Instead of trying to do it with just MSBuild, I used MSBuild to build a deployment package.

MSBuild MyWeb\MyWeb.csproj 
	/target:TransformWebConfig;Package 
	/p:Configuration=Prod;PackageLocation="Deployment\Prod.zip"

That transforms the web.config and creates a .cmd executable that we can call and tell to publish to Azure or IIS is WebDeploy is enabled.

Deployment\Prod.Deploy.cmd 
	/M:https://mywebapp.scm.azurewebsites.net:443/MSDeploy.axd 
	/a:basic 
	/U:$mywebapp 
	/P:[userPWD from your publish profile] 
	/Y

You do still need to download the publish profile from the Azure portal and open it in a text editor to pull out the publishUrl, userName and userPWD. The /Y means that it will go through with the deploy. You can also use /T to do a ‘What If’.

With these commands, I was able to automatically deploy our web app to Azure during our build process. And since I didn’t need to store the publish profile in the .csproj file, I don’t need to worry about someone deploying something from their machine without checking the code into source control.

This article was originally posted at https://hutchcodes.net/2017/09/azure-deploy-command-line

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I’m a Software Engineer at Microsoft working on the Azure Portal. Before that I spent about 20 years developed various business applications at a number of different companies. I have a passion for writing clean, scalable code and sharing what I’ve learned with others.

I also help run the Casco Bay .Net User Group

Comments and Discussions

 
-- There are no messages in this forum --