New Minimod: Generate CSV-files in MVC-Application using CsvHelper

Just uploaded a new Minimod for simple generation of CSV files from a MvcControllers’ action with the help of CsvHelper.


return new CsvHelperFileResult<RecordType, RecordCsvMap>(records, ";")
    FileDownloadName = "my-csv-file.csv"

Find the source code here: CsvHelperMvcActionResult

BTW: Minimods uses nuget to distribute helper-classes as source code instead of compiled libraries.


Apache NPanday 1.4.0-incubating released! .NET for Maven

Update: Allthough I still use it (version 1.5.0, not released) NPanday has been retired from Apache Incubator.

It has been a while since the last release now. 1.2.1 was released at Codeplex in September 2010. Late last year we moved the project over to Apache, where we now wait to grow from incubation top-level Apache project.

Now we are pleased to announce our first official release of NPanday under the Apache umbrella!

Info: This post supersedes my post about the withdrawn 1.3-incubating release.

What is NPanday?

NPanday is a tool for build and release management. It brings Maven to .NET (and Mono). It offers a set of plugins to build and test projects, and it defines all the necessary packaging types for deploying and resolving .NET artifacts.

Apache Maven comes with a great infrastructure for dependency management, artifact transport, artifact repositories, release flows with scm-integration, and much more. If you don’t know Maven, go read here. Maven is great!

There is also a Visual Studio 2005/2008/2010 Add-in for English Visual Studio installations.

Why NPanday, now there is NuGet

Wrong question. Competition is great. Sad though, that at least some of the originators for NuGet didn’t even know about Maven and NPanday. NPanday has been around long before NuGet was initialized.

And Maven is an ecosystem grown over almost 10 years. It has much more to offer than auto-download of dependencies. Still I think we need to integrate the dependency-resolving and deployment part with NuGet and NuGet-gallery (See future plans).

What is new in this release?

NPanday now supports .NET 4.0 and Visual Studio 2010. There has also been major internal improvements. The PAB and UAC directories where removed. Now NPanday uses a clean maven local repository. This also removed the necessity for custom additions to the install and deploy phases – which where duplications of the corresponding maven plugins.

In total we resolved 63 issues including many general fixes. Fixes I worked on:

  • NPanday ran all tools from %PATH% instead of the configured Framework. Now the complicated %PATH% setup is not necessary anymore, because NPanday detects installed SDKs and uses the binaries with absolute paths. You’ll only need to have NUnit on the PATH for executing tests.

    This also included:

    • Better detection of installed SDKs.
    • Better handling for executing binaries and projects that contain whitespaces in their path.
  • The compile plug-in did not bind concrete versions of other NPanday plugins, when registering them in the lifecycles. In many cases it was necessary to specify all pug-in’s versions explicitly in a project’s pom. But now, all further plugins are bound to the current version of the compile plug-in in use.
  • Improved Documentation
  • Better committer experience
  • MVN 3-Support
  • Targeting .NET 3.5 without having Compact Framework installed
  • Better exceptions (exposing root causes many places they previously where hidden, removed silent catches)

For more, read the full release notes.

What are the future plans?

On short notice we will release 1.4.1-incubating, containing 14 more issues.

At the same time we are working on version 2.0, which is a huge internal change. NPanday uses a internal RDF database where it keeps additional information for artifacts and depsendencies. This is obsolete, but lots of work to remove.

We also want to lead NPanday to more .NET-like conventions for directory structures i.e., while still maintaining the Maven-influenced layout.  Of course we also try to improve stability, ease of use and documentation.

My agenda for NPanday:

We are 4-5 active committers from which 2 work full-time on NPanday as of today. We would really like to get more committers involved. Find out on how to develop NPanday in the Get Involved Guide.

Where do I get it?

You’ll find everything you need here: NPanday – NPanday Overview

Downloads: NPanday – Download

Current Docs: NPanday – Documentation

Setting svn:keywords for specific files with Windows Powershell – Or grep with Powershell

In one of my current projects, all source files need to have a file-header looking like this:

// -------------------------------------------------------------
// <copyright company="..." file="Variance.cs">
//   ...
// </copyright>
// <remarks>
//   $HeadURL: https://svn....Api/Utils/Variance.cs $
//   $LastChangedRevision: 1951 $
//   $LastChangedDate: 2009-07-21 $
//   $LastChangedBy: corn_la $
// </remarks>
// <summary>
//   Safe co- and contra-variance for Interfaces in .NET FW 3.5.
// </summary>
// -------------------------------------------------------------

But all to often, the remarks part of the header is uncomplete:

// <remarks>
//   $HeadURL$
//   $LastChangedRevision$
//   $LastChangedDate$
//   $LastChangedBy$
// </remarks>

This means, someone (mostly me) checked in a file with out having configured the svn-keywords property properly.

Now, with “svn propset –R ….” you can reset the properties on all files in a directory recursively. But this is not smart enough to recognize if the properties really changed or not. So it would touch all files specified and boom, every header changes.

What I want to do is setting the properties only on those files that have no properties defined.

Good reason for learning Windows Power Shell! 🙂

Well, here is the command I used:

gci . -r -i *.cs | ? { (gc $_.fullname) -match '\$HeadURL\$$' } | % { svn ps svn:keywords "HeadURL Id LastChangedBy LastChangedRevision LastChangeDate" $_.fullname }

It uses a lot of aliases. The full version would look like this:

Get-ChildItem . -Recurse -Include *.cs 
    | Where-Object { 
        (Get-Content $_.FullName) -match '\$HeadURL\$$'
    | ForEach-Object { 
        svn propset svn:keywords "
HeadURL Id LastChangedBy LastChangedRevision LastChangeDate" $_.FullName 

And here is, what it does:

  1. Getting FileInfos for all C#-files recursively in the current directory
  2. Selecting those FileInfos, where the content has a line ending on “$HeadURL$”, which means there was no property set for HeadURL. Getting and comparing the svn props was even slower 🙂
  3. Calling  “svn propset” on every FileInfo-Object using the FullName as command line argument


  • It was very hard to find good documentation on PowerShell!!
  • Hard to find how to use regex with power shell. The problem was finding the dollar sign, because it is used for variable usage in double quoted strings. It only works properly in single-quoted strings.

    More on regex with powershell
  • It took me a while to find the aliases ?  and % for where-object and foreach-object. Again, hard to find documentation.

Many thanks to Johannes Rössel for helping me with PowerShell on a stackoverflow-Question.

Retrieving the base definition for a PropertyInfo – .NET reflection mess

The Problem

Lets say you got a ClassA with SomeProperty and SomeMethod, plus a ClassB implementing ClassA and overriding both members.

public class ClassA
    public virtual bool SomeProperty

    public virtual bool SomeMethod()

public class ClassB : ClassA
    public override bool SomeProperty

    public override bool SomeMethod()

Now I want to reflect ClassB and find the base definition for each member.

For the virtual method, this is no problem:

typeof (ClassB).GetMethod("SomeMethod").GetBaseDefinition();

But PropertyInfo, does not offer this capability.

The Solution

I created an extension for PropertyInfo, that imitates the functionality of MethodInfo.GetBaseDefinition for properties.

Thanks, David for your suggestions (see first comment)!

public static class ReflectionExtensions
    /// <summary>
    /// When overridden in a derived class, returns the <see cref="propertyInfo"/> object for the 
    /// method on the direct or indirect base class in which the property represented 
    /// by this instance was first declared. 
    /// </summary>
    /// <returns>A <see cref="propertyInfo"/> object for the first implementation of this property.</returns>
    public static PropertyInfo GetBaseDefinition(this PropertyInfo propertyInfo)
        var method = propertyInfo.GetAccessors(true)[0];
        if (method == null)
            return null;

        var baseMethod = method.GetBaseDefinition();

        if (baseMethod == method)
            return propertyInfo;

        var allProperties = BindingFlags.Instance | BindingFlags.Public 
            | BindingFlags.NonPublic | BindingFlags.Static;

        var arguments = propertyInfo.GetIndexParameters().Select(p => p.ParameterType).ToArray();

        return baseMethod.DeclaringType.GetProperty(propertyInfo.Name, allProperties, 
            null, propertyInfo.PropertyType, arguments, null);

Shouldn’t be hard to create a GetBaseDefinition() for EventInfo based on this either.

.NET Reflection Library Mess

I removed this chapter, because it was based on wrong assumptions. The good news is, that the mess isn’t that big, neither 😉