Automatic deployment of an ASP.NET Web Application Project with TeamCity and MSBuild

by Oliver 21. January 2011 20:19

We recently updated one our largest project to use ASP.NET 4.0, and for this matter the new Package/Publish feature including sub-web.configs which is meant to supersede the Web Deployment Project. For a manual deployment there’s a good write-up on the msdn library titled ASP.NET Web Application Project Deployment Overview which shows how and where to set this up. In our case this was not satisfactory because our deployment process is a bit more complicated. We push our changes to a central repository and use JetBrains’ continuous integration server (CIS) TeamCity Professional, which is totally free for our project size, for a continuous integration process. Once TeamCity has pulled and tested the current version, it is supposed to deploy this version to our staging server where we further test the complete site. The key point in an automatic deployment was the management of the different web.config files for the different environments our project is running on. Unfortunately, until yesterday every deployment that included changes to the web.config file – even to the staging server - required a manual step of editing the web.config that live on our staging system (outside of source control!). What we used to do: after a successful build on our CIS we simply copied the web application (files) to our staging server! But as Scott Hanselman wrote: If You're Using XCopy, You're Doing It Wrong! This post inspired us to move along and take advantage of the new possibilities that we were given. In the meanwhile, before switching to .NET 4.0 actually, we also took a shot at the Web Deployment Project way of doing things but never actually got that far as to fully automate the deployment – somehow the setup was not as easy as we hoped. Anyway, we wanted web.config Transforms! So what does our setup look like and what did we want to do?   During local development and testing I use a web.config file that talks to a local DB instance and has some more specific settings. To run the web application on our staging server we need to replace certain values or whole sections in the web.config. For this transformation we use the sub-web.config files, one for each build configuration: Now, with all of these web.config files the simple XCOPY deployment we used to use does not work any longer. We need to trigger the web.config transformation on the build server and then deploy the whole application. As easy as this looks using the built-in menus and dialogs in Visual Studio – it took me quite a while to find how to do this in an automated build, more concretely from the command line. After unsuccessfulle skimming stackoverflow.com for a solution I finally tripped over this very informative blog post on publishing a VS2010 ASP.NET web application using MSBuild. Admittedly, the author focuses on how to publish on the local machine as it’s yet a different process but towards the end he posts the solution I was looking for: 1: msbuild Website.csproj "/p:Platform=AnyCPU;Configuration=Release;DesktopBuildPackageLocation=c:\_Publish\stage\Website.zip" /t:Package This was it! After running this on my machine with my own settings I looked into the folder with the zip file and found the following 5 files: At first I just wanted to take the zip file, copy it to the staging server, unpack it – done! But then I peaked into it… and deeper… and deeper… and… still deeper… until I finally saw our application files underneath this directory: This has got to be one of the longest paths I’ve ever seen and used! How would I automate the extraction of web application files from the zip with such a path? I was already seeing myself hacking away on the command line… But wait: what about those files that appeared next to the zip file? A ci-stage.deploy.cmd and a readme.txt caught my attention – of course, I opened the cmd file first :-D Well… maybe the readme file gives me a shortcut to understanding this and the rest of the 190 lines: Looks promising! I convinced myself to give it a shot. So we set up a new configuration in TeamCity with the following settings: These settings reflect the command line from above with a few minor changes (removed the DesktopBuildPackageLocation and set the /v[erbose] switch to m[inimal]): msbuild Website.csproj "/p:Platform=AnyCPU;Configuration=Release" /t:Package /v:m The second step is to use the generated script, ci-stage.deploy.cmd. I recommend to run the script by hand once using the /T switch just to make sure everything looks alright. In our case we found out that the deployment of the package would have deleted a lot of files, most of all images, from our website. This was not what we wanted! After a quick search I found this question on stackoverflow.com: MSDeploy: “Leave extra files on destination” from command line? So I added this switch to the parameters list in the build step configuration as follows: That’s it! This is all we need on the command line to generate a package that is ready for deployment on the staging server. There are a few more necessary settings, including the DesktopBuildPackageLocation, that can be found in the Package settings window inside the project properties of the web application project: the DesktopBuildPackageLocation can be set here instead of on the command line the website and application name on the destination IIS server that this package should be installed to some more options like excluding debug symbols etc. These settings are saved in the project file and will be used during generation and deployment of the package. That’s all I have to say right now. Happy Coding, Oliver

Balsamiq als Digramm-Tool

by robert 15. May 2010 19:03

Balsamiq ist ein herrlich einfaches Werkzeug um Mock-ups anzufertigen. Ist es auch für die Erstellung von Diagrammen geeignet? Folgendes Bild ist ein Experiment, das die groben Komponenten für ein zu entwickelndes Deployment-Werkzeug unseres neuen Produkts “E-Commerce-Connector” zeigen soll.   Für mich zeigt der Versuch leider eindeutig, dass die Erstellung von Diagrammen mit Balsamiq leider sehr umständlich und langwierig ist. Das Beste Werkzeug für die schnelle digitale Darstellung von technischen Zusammenhängen bleibt für mich immer noch “Enterprise Architect”. Robert

VS2008 Code Snippet zum Repeater-Befuellen

by Stefan 14. September 2009 18:26

Wir befuellen ja haeufig im Frontend einen Repeater. Das einfaedeln der DataSource und das Erstellen und Verknuepfen des EventHandlers fuer ItemDataBound bekommt man mit IntelliSense innerhalb weniger Sekunden hin. Aber wenn man dann den Befuell-Code schreibt, geht es immer wieder los: Wie waren gleich nochmal die ersten 3 Zeilen? Damit ist jetzt Schluss. Einfach die Datei "repeater.snippet" in "Documents/Visual Studio 2008/Code Snippets/Visual C#/My Code Snippets" des Nutzers mit dem man VS ausfuehrt kopieren. Leider zeigt die ReSharper-IntelliSense den Shortcut nicht an, funktionieren tut es trotzdem. Man tippe: rpt [ESC] [TAB] Der Rest versteht sich von selbst: repeater.snippet (1,03 kb)

Soziokratie bei Speak-Friend eingeführt

by robert 18. April 2009 17:31

Durch eine Artikelserie von Ralf Westphal inspiriert, haben wir heute in unserem Mikro-Unternehmen offiziell die SKM (Soziokratische Kreisorganisationsmethode) eingeführt. Das hat zur Folge, dass die Gesellschafter von Speak-Friend, Andrej und Robert, all Ihre autokratischen  Rechte zurückstellen und dem soziokratischen konsent Entscheidungsverfahren Platz machen. Zusammenfassend wird Speak-Friend nach folgenden Prinzipien sich selbst organisieren: Bei der Entscheidungsfindung sind alle in einem Entscheidungskreis beiteiligten gleichberechtigt. Entscheidungen werden nach dem Konsentprinzip getroffen. Daher gilt eine Entscheidung dann, wenn kein Teilnehmer einen schwerwiegenden, argumentierten Einwand gegen einen Vorschlag einbringt. Entscheidungskreise sind hierarchisch organisiert. In unserem Beispiel ist der “Führungskreis” die höchste Instanz. Bei der Einführung haben wir zunächst auf die Wahl von Leitern verzichtet und werden, bevor wir weiter formalisieren, zunächst Erfahrungen sammeln. Der erste Eindruck scheint jedoch zu sein, dass das Konsentprinzip und die damit einhergehende Gleichberechtigung aller, bei der Entscheidungsfindung für uns die zentrale Veränderung darstellt, während die Organisation in (Arbeits) Kreisen unserem bisherigen Arbeitsverfahren entspricht. Aufgrund der kleinen Größe unserer Unternehmung haben wir davon Abstand genommen einen verkleinerten Führungskreis einzuführen. So sind also alle Kollegen (insgesamt 6 Personen) am hierarchisch höchstgestelltem Kreis beteiligt. Die “Organigramm” sieht daher so aus, wobei jeder Kollege in mind. 2 Kreisen aktiv ist:   Die ersten Entscheidungskreisrunden verliefen positiv. Obwohl entmachtet, habe ich insgesamt ein sehr gutes Bauchgefühl und den Eindruck, dass der neue soziokratische Ansatz das Arbeiten freundlicher, fokusierter und reizvoller macht und sich wirtschaftlich positiv auf die Unternehmensentwicklung auswirken wird. Wirkliche Erfahrungen mit der Soziokratie gilt es jedoch erst zu sammeln. Links: Artikelserie von Ralph Westphal Soziokratie auf Wikipedia Linkliste des soziokratischen Zentrums

Zeitfragen

by admin 6. May 2008 18:23

"I don't have time to be classified as difficult, and I don't have time to care." Kim Basinger (Die kreative Antwort auf die Frage, was das mit Produktivität, Software-Entwicklung und der wundervollen Firma Speak-Friend zu tun hat, ist leicht beantwortet: Entwicklungen und deren Erfolg sind zu allererst ein soziales Ereignis und Ignoranz ("Ignorance is a bliss") ein Ninja-Move im Produktivitätsspiel. In den letzten Jahren durfte ich eine Reihe von A-Liga Entwicklern erleben die einfach nicht performed haben. Was nützt ein solcher Entwickler der im Zweifelsfall ein Webframework mit einer Nadel in drei Nächten Binär auf eine Festplatte ritzen könnte, wenn er in drei Wochen nicht die Motivation findet ein paar einfache Formular zu bauen? Oft nützt ein dickes Fell und Immunität für Fremdmeinungen, um Dinge vom Tisch zu bekommen.)

Aufmerksamkeits-Management

by admin 22. February 2008 18:12

Aufmerksamkeit ist unser kostbarstes Gut. Merlin Mann gibt praktische Empfehlungen wie man mit einer stetigen Flut von Anfragen, Aufgaben und Information umgehen kann. Absolut Hörenswert! [http://www.43folders.com/2008/02/14/time-attention-talk]

Resharper 4.0

by admin 16. February 2008 10:58

Darauf habe ich die letzten 2 Monate sehnsüchtig gewartet, ein Resharper das die neuen .NET 3.5 Spach-Features unterstützt. Seit dem 15.2 gibt es die ersten „ReSharper 4.0 Nightly Builds“. Die Installation und Benutzung ist soweit reibungslos, bei Stefan Lieser ebenfalls. Viel Spass damit :-)

Programmieren und 10 Finger schreiben

by admin 5. February 2008 18:12

Mich hat schon einige Male der Umstand verwundert, das erstaunlich viele Programmierer nicht mit 10 Fingern schreiben können - wo doch die Tastatur Ihr Hauptarbeitswerkzeug ist. Nicht alles im Softwareentwicklungsprozess ist Analyse oder Design. Natürlich wird nicht die meiste Zeit mit Tippen verbracht, doch hilft es sicher dabei, auf den Monitor schauen zu können. Eine schnelle Eingabe, schafft mehr Zeit für anderes. Dieser Schnell-Schreibtest offenbart, das min. 48 000 Schreiber schneller sind als ich. Andrej, der Mausschubser gehört mit 72 Worten auch dazu - Streber! :-). 68 WörterUnd wie schnell seit Ihr?

Arbeitsoptimierung als Spiel

by admin 20. October 2007 22:29

„Seriosity“ möchte Unternehmens-Produktivität spielerisch erhöhen und übernimmt Konzepte aus Multiplayer Spielen um Arbeitsprioritäten zu gewichten und zu optimieren. Alltagsökonomie wird Bunt und kann Spaß machen.  Der Ansatz, Alltag als Spiel zu begreifen oder zu betreiben ist sehr verlockend. Gute Computer-Spiele bieten einen endlosen Strom von erreichbaren Aufgaben ohne zu überfordern. Ein Zustand der wenn beim Arbeiten erreicht, zugleich befriedigend als auch produktiv ist.

Von der Idee zur Webseite in 2:20h

by admin 19. October 2007 01:29

Es lebe die Informationsrevolution. Tausende von wunderbaren OpenSouce Webanwendungen aus allen nur erdenklichen Segmenten warten darauf verwendet  zu werden. Ob ein Content Management System mit hunderten von Komponenten, eine Enterprise fähige Shop-Lösung oder eine Project Management Werkzeug für Entwickler inklusive Versionskontrolsystem Zugriff alles ist verfügbar. Doch wie lange dauert es von der Idee, bis zur Umsetzung? Hier ein einfaches Beispiel. Wir benötigen eine Domain, 2 Email-Accounts, eine Präsentationseite mit CMS Eigenschaften, einen Blog und wir wollen alle Inhalte editieren können. Hier die Zeiten:   Domain registrieren 10min. Emails einrichten 10min. Domain auf Server einrichten 5min OSS Lösung auf Server installieren 30min Anpassung der Lösung: Strukur und Skin anpassen, Übersetzungen pflegen. 1h Benachrichtigungsemail verfassen 25min Fertig :-) Von der Anforderung bis hin zur fertigen Lösung in 2:20h. Na klar, das Scenario ist deutlich das einfachste was ich je erlebt habe. Alles funktionierte „Out-Of-The-Box“. Der Server war schon vorbereitet. Die Datenbanken schon da. Die Backuplösung schnurrt von allein. Firewall und IP-Filter sind eingerichtet. Das OSS Produkt kann alles, was gebraucht wurde und war schon bekannt. Eines der Templates hat für den Zweck vollkommen ausgereicht. Das Logo hat gepasst. Und noch war keine Zeit für Support anfragen :-) Achso und natürlich hat es 2 1/2 Stunden gedauert bis die Domain verfügbar war, aber ich zähle das jetzt mal nicht als Arbeitszeit. Insgesamt eine schöne Erfahrung.

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.