Welcome!

Microsoft Cloud Authors: Janakiram MSV, Yeshim Deniz, David H Deans, Andreas Grabner, Stackify Blog

Related Topics: Microsoft Cloud, Java IoT, Microservices Expo, Linux Containers, Agile Computing, @DevOpsSummit

Microsoft Cloud: Article

What Should Be in Your .NET Toolkit? [#DotNet]

The easiest way to cover the list of deployment steps and the best tools to use

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
Whatever build server you're using for doing continuous integration (CI), it is an ideal tool to trigger your deployments, as it provides core benefits of audit (you always know who/when triggered deployment at which version). Just set up deployment build plans for each platform to which you want to deploy. The amount of deployment planning largely depends on branching and application lifecycle management (ALM) strategies you employ. For example, you could have something like the following:

  • Integration - Builds from master branch to deploy to integration platform where UI tests are executed as of the latest developed source code. Triggers whenever a new set of commits appears in the repository.
  • QA - Builds from master branch to deploy new features to QA environment whenever QA and Dev teams agree they need a new version validated. Triggered manually.
  • Release - Builds from a particular commit of master branch to deliver a validated version of the application to production environment.

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 and MSBuild teams have been working hard to make the deployment experience a smooth one in the past few years, and we have some pretty neat features these days as a result (for example, you can configure basic auto-deployment in a few steps).

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
One of the most frequent deployment errors when done manually is incorrect configuration. Connection strings, timeouts, custom errors, external services endpoints, and much more can be different in production compared to development; moreover, configuration evolves along with the application, so every time a new version arrives to production, intelligent merge of dev and production config files is required. I don't know a single dev/ops person who likes merging these files by hand. If you're still doing that, stop it now. You can spend your time doing something much more useful. Config transformations to the rescue.

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:

For example:

  • Configuration-specific transformation turns on custom errors for release (needed in release regardless of the environment used);
  • Publish-profile-specific transformation changes connect strings (which are different across different environments).

Now your process of configuration maintenance is simple and defined:

  • Production configuration is always built automatically from dev configuration;
  • Transformations are versioned in the version control system and evolve naturally with source code and dev configuration changes.

No more manual merging of dev and production configuration. No more storing of configuration changes in emails/wiki pages. No more headache.

Database updates
Your database changes as your source code changes, so it makes perfect sense to version both together (otherwise they will get out of sync at some point). There are a couple of ways to do so, but these days, most of our teams tend to use migration frameworks (as they provide fine-grained control over what's happening). We have plenty of migration frameworks for .NET (e.g., FluentMigrator, EntityFramework migrations); simply use the one you like most.

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
MSBuild is your best friend in executing all those deployment steps. It has some built-in capabilities to copy files, run executables and manage configuration properties. For example, use WebDeploy client to control IIS (recycle ApplicationPool, take the application offline before deployment, bring it online after deployment).

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.

Summary
Every new practice takes time to adopt, but with modern tools, implementing automatic deployment can be quite easy. If you're sold on the idea but are unsure on where to start (or can't sell it to your manager), I suggest you to start with automating QA builds, as they require less custom steps (e.g. you don't' necessarily need to take the application down during QA deployment). Once this is in place, you'll have the proof you need to confidently expand deployment to production.

More Stories By Ivan Antsipau

Ivan Antsipau is a senior .NET developer at Itransition specializing in architecting and implementation of business-specific web applications. With a specialist degree in Radiophysics and Computer Science, a knack for team leading, and years of hands-on programming experience under his belt, he sees the key to sustainable and accelerated delivery of software projects in elimination of stressful manual efforts with the help of continuous integration and automated testing.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Agile has finally jumped the technology shark, expanding outside the software world. Enterprises are now increasingly adopting Agile practices across their organizations in order to successfully navigate the disruptive waters that threaten to drown them. In our quest for establishing change as a core competency in our organizations, this business-centric notion of Agile is an essential component of Agile Digital Transformation. In the years since the publication of the Agile Manifesto, the conn...
SYS-CON Events announced today that App2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct. 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. App2Cloud is an online Platform, specializing in migrating legacy applications to any Cloud Providers (AWS, Azure, Google Cloud).
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, will introduce two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a mu...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
Mobile device usage has increased exponentially during the past several years, as consumers rely on handhelds for everything from news and weather to banking and purchases. What can we expect in the next few years? The way in which we interact with our devices will fundamentally change, as businesses leverage Artificial Intelligence. We already see this taking shape as businesses leverage AI for cost savings and customer responsiveness. This trend will continue, as AI is used for more sophistica...
SYS-CON Events announced today that SourceForge has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. SourceForge is the largest, most trusted destination for Open Source Software development, collaboration, discovery and download on the web serving over 32 million viewers, 150 million downloads and over 460,000 active development projects each and every month.
SYS-CON Events announced today that Massive Networks will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Massive Networks mission is simple. To help your business operate seamlessly with fast, reliable, and secure internet and network solutions. Improve your customer's experience with outstanding connections to your cloud.
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that WineSOFT will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Based in Seoul and Irvine, WineSOFT is an innovative software house focusing on internet infrastructure solutions. The venture started as a bootstrap start-up in 2010 by focusing on making the internet faster and more powerful. WineSOFT’s knowledge is based on the expertise of TCP/IP, VPN, SS...
SYS-CON Events announced today that Akvelon will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Akvelon is a business and technology consulting firm that specializes in applying cutting-edge technology to problems in fields as diverse as mobile technology, sports technology, finance, and healthcare.
SYS-CON Events announced today that TechTarget has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. TechTarget storage websites are the best online information resource for news, tips and expert advice for the storage, backup and disaster recovery markets.
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
SYS-CON Events announced today that Dasher Technologies will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Dasher Technologies, Inc. ® is a premier IT solution provider that delivers expert technical resources along with trusted account executives to architect and deliver complete IT solutions and services to help our clients execute their goals, plans and objectives. Since 1999, we've...
DevOps at Cloud Expo – being held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real r...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, will present a step-by-step plan to develop your technology implementation strategy. He will discuss the evaluation of communication standards and IoT messaging protocols, dat...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
Elon Musk is among the notable industry figures who worries about the power of AI to destroy rather than help society. Mark Zuckerberg, on the other hand, embraces all that is going on. AI is most powerful when deployed across the vast networks being built for Internets of Things in the manufacturing, transportation and logistics, retail, healthcare, government and other sectors. Is AI transforming IoT for the good or the bad? Do we need to worry about its potential destructive power? Or will we...
SYS-CON Events announced today that App2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct. 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. App2Cloud is an online Platform, specializing in migrating legacy applications to any Cloud Providers (AWS, Azure, Google Cloud).
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.