Most Read This Week
What Should Be in Your .NET Toolkit? [#DotNet]
The easiest way to cover the list of deployment steps and the best tools to use
By: Ivan Antsipau
Sep. 24, 2014 10:00 AM
These days, implementing automatic deployment for .NET web projects is easier than ever. Drastic improvements started in Visual Studio 2010 when basic deployment strategies and tools were incorporated into VS itself. Yet, documentation was quite poor at that time, so you had to scour the Internet to find good tutorials in blogs or conference videos. Things have been constantly improving since then; now, we have even more functionality available out-of-the-box and documentation provided in a way that allows you to get started from zero understanding of the process to working deployment in less than two days. Some good places to start are this tutorial for an end-to-end guide on configuration and MSDN's overview.
In this article, I will show you the easiest way to cover the list of deployment steps and the best tools to use.
Trigger your deployment from build server
You will want to add similar build plans for release or feature branches if you are using them in your workflow. You could also add a nightly build plan to deliver a nightly version of your application for preview (this is what we do when stakeholders need better visibility of the progress to get faster feedback without distracting the team).
A build server guarantees that a build plan is triggered on the source code exactly as of specific commit, so you're safe from "wrong source code version deployed" kind of errors.
Deployment out-of-the-box (configuring deployment in several clicks)
Visual Studio has a concept of publish profiles. In a nutshell, a publish profile is a versioned (you should store it in the repository) XML file that holds information about the destination environment and deployment settings. In a simple scenario, you'll have a publish profile for each of your platforms.
Right-click your project in solution explorer and go to the publish dialog:
You can add a publish profile using manage profiles dialog (this is what you do for your on-premises environments). Just fill in WebDeploy endpoint address and password - and you're done.
For those using Azure: ready-to-use publish profiles can be downloaded directly from Azure, which is even easier.
Now check-in your freshly generated profile and modify your deployment build plan to execute the following:
Msbuild.exe Web.csproj /p:DeployOnBuild=true /p:Configuration=Release /p:PublishProfile=staging /p:Password=p0ssw0rd
And you're done. MSBuild will take care of building your application in the desired configuration (release) and publishing it to the desired environment (staging in this case).
You can extend/customize packaging to address your specific needs (e.g., do not Remove /Uploads folder). Check out Sayed Hashimi's blog for some interesting examples.
Version your configuration
Config transformations have been introduced in VS 2010. Essentially, config transformation is a simplified version of xslt to transform your .config files in an efficient way. A transformation is just another .config file sitting next to your original .config file and applied upon publish. Transformation files use a very simple language.
You can have configuration-specific (release/debug) and publish-profile-specific (QA/production) transformations. MSBuild chains transformation files so that first configuration-specific transformation is applied and then profile-specific transformations finish the job:
Now your process of configuration maintenance is simple and defined:
No more manual merging of dev and production configuration. No more storing of configuration changes in emails/wiki pages. No more headache.
Migrations can be configured to update the database on the first use (when application starts), or you can execute a console migrations runner in your migration script. While the former option is easier, I strongly recommend the latter (running database migrations as part of you deployment script), as this allows you to detect errors before users hit your application.
To do this, just add this to your deployment build:
Migrate.exe MyMvcApplication.dll /startupConfigurationFile="..\web.config"
Deployment scripting with MSBuild
Use extension libraries to do the rest (set ACL, backup database, etc):
For example, use the SqlExecute task to back up the database before deployment. Or use a folder task to set ACL permissions to the uploads folder. Check out the list of tasks in these libraries, and you can do pretty much everything your deployment process requires without much effort so that no manual interaction is needed.
Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Today's Top Reads