Automating .NET Deployments
Setting up the tools for a continuous integration (CI) environment can seem like a daunting task. There are dozens of tools and configuration approaches to take advantage of that it can be overwhelming to even get started. Different tools are tailored to different development technologies so choosing the right tools for the job is the most important step in building a CI environment. If .NET is the primary technology, then utilizing TeamCity and Octopus Deploy on a Windows Server is a no-brainer for automating deployments.
TeamCity is one of the most popular build management and continuous integration platforms available today for .NET solutions. It also doesn’t hurt that it was built by JetBrains, the same company that created ReSharper, dotCover, dotPeek, and many other great tools for .NET development. Octopus Deploy is designed specifically to deploy .NET solutions, and was even created by a .NET developer who was tired of writing the same PowerShell deploy scripts. Both of these tools are extremely user friendly and come with out-of-the-box features for .NET solutions. TeamCity has a built-in integration to build Visual Studio solutions and can be easily configured to use MSBuild and other compilers to build .NET solutions. Octopus Deploy can deploy Windows Services, IIS websites, and generic .NET solution packages right out of the box. With these two tools and a little configuration, having an automated CI environment is simple.
In a large environment with hundreds of projects, it may make sense to have a multi-server environment for scalability. For the topic of building a simple CI environment, we will focus on the scenario where small team of developers are building a new .NET web application. It may be questionable if a full CI environment is even necessary and worth the investment for a small team with one web application, however, using TeamCity and Octopus together requires no more than a half day’s work for one person, not to mention it is completely free with a limitation on number of users and projects. This investment is quickly realized when the team of developers no longer has to manage and deploy new code, ever.
To get started, a dedicated Windows Server needs to be identified. Either build a new VM in Windows Azure, configure a new on-premise machine, or simply, use the same server as the development environment. There are no rules that say SQL Server, TeamCity, Octopus, and custom .NET web applications can’t run all on one server, in fact, it makes the perfect development/testing environment for a small team. Once a server has been identified to be the “Build” server, there are only a few installation wizards and configuration steps to walk through to have the full CI environment up and running.
Installing TeamCity is quick and easy. Download the latest version from the JetBrains website and walk through the wizard. In a matter of minutes, the Apache based web site will appear. Step through the configuration screens to set up the backend database and data directories. While TeamCity offers options to build solutions using an installed version of Visual Studio, the Build Tools for Visual Studio offered by Microsoft are a free and easy way to compile the code using MSBuild. Install the necessary .NET frameworks and move on to Octopus Deploy.
Octopus Deploy is again a simple installation wizard to step through. Use the same SQL Server for the database backend and accept the default options, the Octopus web portal is ready to go. Octopus offers a plugin for TeamCity to create and deploy releases automatically, it’s as simple as dropping the zip file in the plugins folder in the TeamCity data directory and restarting the server. Octopus uses a concept called tentacles for deploying projects. Each server the code will run on will need to have the Octopus Tentacle service installed and running. When a deployment is requested for a particular environment, Octopus will push the package to the desired server through the Tentacle service. Install this on the same server and configure it as the development environment.
Now that the major building blocks are in place, it’s time to link everything together. There are two primary actions TeamCity will be configured to perform, these are called build configurations – first build, then deploy. Optionally, add testing and code quality checks in between. TeamCity can connect to a number of source control platforms, including a built-in API for connecting to GitHub. Create a new project in TeamCity and add the Build configuration by pointing to the code repository. Use the MSBuild runner type and add the option for OctoPack so that the code will be packaged into a Nuget package like magic. Enable the Nuget server in TeamCity and the packages will be available for consumption, by the team, or primarily Octopus. Create the project in Octopus and add a Deploy configuration in TeamCity. All TeamCity needs to create and deploy a release through Octopus is the name of the project and an API key. Once these are all configured, simply commit and push new code and watch as TeamCity and Octopus automatically build and deploy the code to the target server.
Continuous integration is meant to make everybody’s lives easier, not complicating it further. Now with TeamCity and Octopus, setting up a full CI environment is easy and free. A detailed guide on the steps to create a full build server as described above is available here: Guide: Building a Simple .NET Build Server.
Anexinet is a leading provider of technology consulting services with an advanced capability in DevOps and the full CI pipeline. Reach out to us to see how we can add value to your organization.