This first post is about preparing our project for Octopus deploy. This example is based upon a standard Asp.Net MVC application.

Preparing involves some knowledge of Teamcity and Octopus deploy. Because deployments in Octopus are done using NuGet, we need the possibility to create a NuGet package from our website.

First we need some deeper knowledge of MsBuild and targets. Open the Developer Command prompt and navigate to your project directory. This is the directory where you can find the csproj file(when using c#). Developer Command prompt can be found under the Visual Studio tools.

Opening the command prompt we can use the raw power of MsBuild, actually we are doing exactly the same thing as Visual studio without the GUI.

First of all, let’s create a build:

This will just build the project, nothing special. Now let’s clean the project:

Cleaning removes all assemblies from the bin directory and the temp directories in the obj folder. Remember, every project must survive a clean build! Ever! If you need a reference to a library, create a ‘libs’ directory and refer to that location. Don’t paste the dll in the bin directly, never! Cleaning and Building should produce a new working application.

You can add a configuration to the command:

This will build the project using the Release configuration, defined in the project itself.

Ofcourse, it is possible to combine targets:

These ‘clean’ and ‘build’ targets are ‘internal’ msbuild targets. Besides using these predefined targets, it is also possible to create your own target. And that’s is precisely what I am looking for.

Using tools like Teamcity and Octopus deploy forces you to think ahead. Running an application locally in not enough. You must lean to think like TeamCity. It will take some time but it’s a great adventure 😉

The first step in creating a package is offering tools for TeamCity to build the project and copy the produced output to a given directory. Unfortunately MsBuild doesn’t offer this out of the box, so we have to create our own target:

This target requires a parameter called ‘PublishDestination’ so we place this new parameter in the project file:

2015-03-28 15_15_56-E__VsProjects_TeamcityOctopus_TeamcityOctopus.Web_TeamcityOctopus.Web.csproj - SWhen running a build running this target, MsBuild copies the created files in the temp directory(obj) to the given PublishDestination. You can accomplish this also using publishprofiles but using Teamcity we need a seperate, clean directory which contains a nice clean Release build of our project.

We can test this target by using this in our MsBuild command:

(note the PublishToFolder target!)

2015-03-28 15_26_56-TeamCityOctopusAbove the result of the build. A nice clean release build!