Creating a new module in ‘discoverize’ – using multi-file templates and good ol’ batch scripts

by Oliver Fri, July 15 2011 09:07

For our portal software discoverize I was looking for a way to create new modules faster and more reliably. The basic structure would always be the same, so a Visual Studio multi-file template seemed appropriate:

module

Well, unfortunately I didn’t find a way to create new folders with that approach. Multi-file templates really do what they say: they create multiple files from templates. Nothing else.

So I put together a short batch script that would create the directory structure needed for any new module:

image

I can quickly open a new command line window by using any one of several Visual Studio extensions (e.g. PowerCommands for Visual Studio 2010):

image

… and simply run:

image

Now going back to Visual Studio we have to include the new Feature folder in the project:

image

Then hit Ctrl + Shift + A to open the Add New Item dialog, select ‘Discoverize Module’ and type Feature in the Name textbox (unfortunately, there seems to be no easy way to automatically put the name of the folder inside that textbox):

image

This step will generate three code files, that are the backbone of every module: FeatureConfig.cs, FeatureModule.cs, and FeatureViews.cs. Finally, our multi-file item template comes into play!

Handling the multi-file template

The multi-file item template for a new module consists of four files: the template definition file Module.vstemplate and the template code files Config.cs, Module.cs, and Views.cs:

image

Those four files have to be packed into a zip file and copied to a folder underneath %UserProfile%\My Documents\Visual Studio 2010\Templates\ItemTemplates\ – I put this one into Visual C#\Code. That’s how it appeared under the Visual C# –> Code section in the Add New Item dialog.

Since it is somewhat cumbersome to zip and copy updated versions of the template (especially during early development where I keep adjusting and tuning the template code), I put together another batch file that does that for me. It basically does three things:

  1. Get the name of current folder to use as name for the zip file (found the solution here)
  2. Use 7-zip to zip the four files.
  3. Copy the zip file to the VS custom template directory.

image

The real script contains some safety nets and more output so that in case it won’t work across all developer machines I can get quick feedback as to what exactly didn’t work instead of just “it didn’t work”.

Happy Coding!

Tags: ,

Software development | developer | Tips & Tricks | Productivity

The Teamaton tool belt: a collection of small but useful tools for every day development and administration

by Oliver Wed, January 26 2011 20:30

Today: a simple hosts file editor

Today I set up a new project on GitHub: the Teamaton tool belt! It shall serve us as a central store for small tools, probably mostly command-line, built for a single purpose. The first tool in our new tool belt is: HostsEditor.

I wrote this small command line utility after reading this blog post: http://apdubey.blogspot.com/2008/09/edit-host-file-by-batch-file.html. We were looking for an easy way to edit the Windows hosts file from a script for a larger development environment setup that we wanted to fully automate including IIS website, bindings and new entries in the said hosts file. Of course, for a one-timer echo does the job, but don’t try to run the setup script twice on the same maching – you’ll get duplicate entries very quickly.

Reading about how other people are asking the author of the above post how to avoid the duplicates or how to erase entries from the hosts file, I set out to simply write such a utility myself and share it with the rest of the world. If there is one other person out there to whom it will be useful I will be happy.

So, HostsEditor does the following:

  • Adds and removes entries to and from the Windows hosts file.
  • Automatically backs up the original hosts file to hosts.bck.
  • Does not add duplicate entries; instead prints a warning.
  • For usage in automation scripts there is /q switch to suppress all info messages.

hostseditor-usage

That’s all there is to it for now. But there’s more to come!

Stay tuned, Oliver

Tags:

Build | Productivity | Automation

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

by Oliver Fri, January 21 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?

setup 

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:

web-configs

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:

package-folder

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:

zip-path

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

deploy-cmd

Well… maybe the readme file gives me a shortcut to understanding this and the rest of the 190 lines:

readme

Looks promising! I convinced myself to give it a shot. So we set up a new configuration in TeamCity with the following settings:

tc-config

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:

web-deploy

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.

package-settings

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

Tags:

ASP.NET | Automation | Productivity | Software development | Web Applikationen

Balsamiq als Digramm-Tool

by robert Sat, May 15 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.

Balsamiq-als-Digramm-Tool 

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

Tags:

Productivity

VS2008 Code Snippet zum Repeater-Befuellen

by Stefan Mon, September 14 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)

Tags:

Productivity | Tips & Tricks | Visual Studio

Soziokratie bei Speak-Friend eingeführt

by robert Sat, April 18 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:

4-18-2009 4-11-15 PM 

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:

Tags:

Productivity

Zeitfragen

by Robert Tue, May 06 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.)

Tags:

Productivity | Unterhaltung

Aufmerksamkeits-Management

by Robert Fri, February 22 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]

Tags:

Productivity

Resharper 4.0

by Robert Sat, February 16 2008 10:58

image 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 :-)

Tags:

Productivity | Software development

Programmieren und 10 Finger schreiben

by Robert Tue, February 05 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?


Tags:

Productivity