I can sum my experience with trying to use MSDeploy and Powershell together with a single word: hell. MSDeploy.exe does not play nicely with PowerShell, but thanks to some help from James and a lot of trial-and-error, I’ve got it sort-of working now. Here’s a tail of my journey. Hopefully you, brave reader, will learn from my mistakes. THAR BE DRAGONS HERE.
It began with the automation of deployments
This journey started from a desire to automate our deployment processes. We have three different software applications that we host under a SaaS model, and only one of those has a deployment that even remotely qualifies as semi-automated. Making deployment less painful typically leads to more frequent deployments and happier developers, so I set out to automate things. I have previously used MSBuild and PowerShell to automate things, but that was several years ago, and the tools have changed. Today, we have a new tool to help with deploying web applications: the Microsoft Web Deployment Tool, or MSDeploy. FTA:
The Web Deployment Tool simplifies the migration, management and deployment of IIS Web servers, Web applications and Web sites.
Basically, MSDeploy gives us some great functionality for remote deployments. With it, I can deploy files, execute commands remotely, run SQL scripts, etc. On paper, this seemed like a great tool. Using it, I should be able to deploy applications without having to log on to the target servers at all.
So, with MSDeploy installed and ready, I decided I would use PowerShell to drive things instead of MSBuild or batch scripting. After all, PowerShell is the future of the Windows Shell. And MSDeploy is new hawtness. So the two will surely play nice together, right? Right?
You seek the 2.0 shell?
Before starting, I decided I would install PowerShell 2.0. It was required for one of the tools I was using (which I’ll cover in a future post). I was running Vista with PowerShell 1.0 installed. So I hit up Google to find the 2.0 release:
Hmm, none of the top results looked like a download page for the final version. I didn’t want a CTP, I wanted the final version. Bing was not much better:
Bing returned a blog post indicating that the RTW version shipped, but no link in the first few results (yes, I am one of those searchers who only scans the first few hits before abandoning my query and trying a different one). I finally found the PowerShell portal on TechNet, which did include a link to download PowerShell 2.0. PS2 is part of the Windows Management Framework, which is intuitively* disguised as KB968929. Suggestion to Microsoft: how about making it a little less difficult to find PowerShell?
*SarcasmLevel = int.MaxValue;
There can be no alliance between PS and MSDeploy
Despite the initial frustration of finding and installing the latest PowerShell, I had high hopes that things were going to go smoother now. I had numerous examples of how to use MSDeploy.exe from the command-line, and the documentation actually seemed pretty solid. You can imagine my surprise when I tried running a simple example and was greeted by the following:
Note: The comments are mine, not MSDeploy output. There is no MSDeploy output. Nothing. At all. Until I forcibly end msdeploy, I can type whatever I want, and it just sits there quietly.
I’m not a PowerShell guru, but I don’t think that is normal behavior. I found a handful of blog and message forum posts scattered across the web reporting similar behavior when using MSDeploy with PowerShell. After reading the IIS blog, I started to suspect that using MSDeploy with PowerShell, at least through the command line, was actually not supported. This really dashed my hopes:
And let us know if you want to use Web Deploy with PowerShell, we’re interested in hearing about what tasks you’d like to accomplish and why!
I bet the use cases for MSDeploy with PowerShell are the same as using MSDeploy from the old CMD shell. I’m really surprised that PowerShell is apparently not fully supported right out of the box. I think Microsoft did realize that people might want to use the tools together. Why else would they have had PowerShell cmdlets in the early preview releases? Unfortunately, these cmdlets were removed from the final version (see the last comment).
More digging around led me to some actual working examples of using MSDeploy with PowerShell, but it seemed a lot less elegant than running msdeploy.exe.
An old friend comes to the rescue!
Despite this setback, I wasn’t ready to give up yet. My initial solution was to wrap msdeploy.exe in a (very) simple batch script that I could invoke from PowerShell, but James gave me a better solution: invoke msdeploy.exe through cmd.exe directly! I created a function to wrap the invocation, like so:
function PushToTarget([string]$server, [string]$remotePath, [string]$localPath) { cmd.exe /C $("msdeploy.exe -verb:sync -source:contentPath=`"{0}`" -dest:computerName=`"{1}`",contentPath=`"{2}`" -whatif" -f $localPath, $server, $remotePath ) }
Now I can use MSDeploy to sync files to my production servers. In a future post, I’ll show you how capability fits in to our larger deployment process.
Excellent post, A++++++, would read again.
Seriously though, looking forward to what you find out. On our list of "internal improvements" is getting CI builds and automatic deployment to internal QA and staging, so this will be really good to hear your experience.
Along the same lines – what do you use for a build server? TFS isn’t an option for us just yet (what we used at my last job), and my boss had been checking out Nant.
We use CruiseControl.NET as our build server right now, but mostly because it was the best thing available 4 or so years ago when we set it up. CCnet then invokes either NAnt or MSBuild scripts to build, test, and in some cases analyze the code and generate reports. I like CCnet’s capabilities, but I’m not a big fan of the verbose XML config. Today, I think I’d at least look at TeamCity first. I’m also using psake instead of MSBuild now. It has some major deficiencies, but nothing that can’t be overcome fairly easily, and because it’s based on PowerShell, you have easy access to all of .NET. My next post will touch more on psake and how I’m using it.
Such a stunning article. Thanks for putting up this information..
Nice blog, not like some boring ones. I had a good read, Thnx! Will keep an eye out for more of your blogs.
Your RSS feed is not working on my site. I am currectly using Google Chrome.
It’s a rare find for a nice blog like this. I enjoyed it. Kudos to you. Have a nice day!
Interesting blog. I usually like to read blogs like this one. Thanks! Have a great day.
Bonjour, I I came across your website on yahoo and browse alot of your other posts. I just added you to my Google News Reader. Keep up the fantastic job. Looking forward to reading more from you in the future. You know, I have to tell you, I really enjoy this blog and the insight from everyone who participates. I find it to be refreshing and very informative. I wish there were more blogs like it. Anyway, I felt it was about time I posted, I?ve spent most of my time here just lurking and reading, but today for some reason I just felt compelled to say this.
I truly enyojed this awesome website. Please keep it up. Regards from John…
Salutations, I I found your website on google and browse alot of your other posts. I just added you to my Google News Reader. Keep up the superb job. Looking forward to reading more from you in the future. You know, I have to tell you, I really enjoy this blog and the insight from everyone who participates. I find it to be refreshing and very informative. I wish there were more blogs like it. Anyway, I felt it was about time I posted, I?ve spent most of my time here just lurking and reading, but today for some reason I just felt compelled to say this.
Good thread. Cheers!!
Thanks for another fab article – I enjoyed that!
How long have you been doing this?
I really don’t follow that last part
Great Blog I love the lay out and the color scheme is it possible to get a copy of your theme? Please send me an email at [email protected]
Good thread. Cheers!!
I must say this really is the fourth time I have read your web site and Im likein it! I added your weblog to my rss reader. Will be waiting to see more updates!
One has to think through it before coming to a conclusion on about it,beautiful site I like the header.
I don’t anyways agree with people, but I read a few posts here and like what you have to say, keep up the good work.
Intriguing articles. I favorited your site. I’m searching for other blogs that have an audience that would find value from a new page I maintain on akita dogs. Let me know if you want to exchange some posts or content. I think we could both get value.