MSBuild Code Analysis (on a build server) Friday, 17 Apr, 2015

It is possible to setup your build server to run code analysis on your solution/projects, without having to install VS on your build server.

The answer is here:

I'm not going to reproduce the code here, there is no point. This post is just a reminder to myself as to where I found the solution to this.

Gitlab and Active Directory Wednesday, 15 Apr, 2015

Gitlab is an open source 'clone' of Github, although I don't think it's much of a clone anymore, to be fair. The Enterprise edition has full Active Directory support, and the Community edition does not.

The integration with Active Directory is of great benefit. To get the most out of it, I think that you would need to upgrade to the Enterprise edition, as it adds a number of additonal integrations which look to be really usefull for larger organisations with multiple projects and development teams.

It is possible to configure the Community edition to integrate with Active Directory, to the extent that you can restrict exactly who is allowed to login in. You have to manually configure the users permissions on groups/projects though. In the Enterprise edition, the tighter integration means that you can match up Active Directory groups with groups in Gitlab, and control access both to the server, and groups/projects, all through Active Directory.

Here is the ldap section from my gitlab.yml (please be aware, I'm no Active Directory expert):

enabled: true
      label: 'domain'
      host: ''
      port: 389 
      uid: 'sAMAccountName'
      method: 'plain' 
      bind_dn: 'CN=Git Lab,OU=AB,OU=example,DC=example,DC=com'
      password: 'secret'
      allow_username_or_email_login: true
      active_directory: true
      base: 'OU=example,DC=example,DC=com'
      user_filter: '(memberOf=cn=devs,ou=groups,dc=example,dc=com)'

The bind_dn is for a user called 'Git Lab', and you must suppoly the password. This user was expressly setup just for this, but you can use any user. The base is the level of Active Directory that Gitlab searches for users from. Finally, the user_filter states that users must members of devs in order to be able to login.

ASP.Net Bootstrap 3 form control width Thursday, 19 Mar, 2015

Having just been stumped on this for longer than I care to admit, and only finding the answer to my problem buried in a comment on StackOverflow, I'm posting it here for my own future reference:

Q: Using ASP.Net MVC with Bootstrap 3, why won't my <input> stretch to the full width of a <div class="form-group">, even though I am putting form-control on the css class?

A: Because Microsoft override input, select and textarea to have max-width: 280px in the default Site.css which is added to new projects. Removing this will allow the 100% width from form-control.

Fluent NPoco mappings with StructureMap Tuesday, 17 Mar, 2015

I like using NPoco, it's a really nice library that allows you stop having to write raw ADO.NET. Recently I just switched one of my projects at work to use the Fluent Mapping features, essentially so that my POCO's do not need to have the mapping attributes in them.

I started wth the example on the NPoco wiki of creating a database factory, and adding the mapping class to the fluent configuration. As the number of mapping classes has grown, this has quickly become unwieldy and a bit of a maintainance issue.

As I already utilise Structuremap in the application, I wanted to configure it to automatically pick up my mapping classes and build the configuration object for me. This is easy to in the registry:

public DefaultRegistry()
        scan =>
            scan.With(new ControllerConvention());

    For<FluentConfig>().Use(context => FluentMappingConfiguration.Configure(context.GetAllInstances<IMap>().ToArray()));
    For<IDatabase>().HttpContextScoped().Use(context => context.GetInstance<DatabaseFactory>().GetDatabase());

The mapping classes must inherit from Map<T>, which itself inherits from IMap. Thus we can confidently add all types of IMap in the scan.

Then an instance of FluentConfig must be registered, which can be done with an overload of .Use, from which we get the StructureMap context and pull out all the types of IMap which have been found and pass it to the static .Configure method of the FluentMappingConfiguration, which constructs the instance.

The DatabaseFactory (see below) is then registered, and it accepts a 'FluentConfig' instance in its constructor. As per the original example on the NPoco wiki, it is marked as a singleton to ensure that only one instance is created, so that the mappings do not get registered more than once. I don't know what would happen if the mappings were to be registered more than once, but I assume that it would be a Bad Thing™.

Then, for the NPoco IDatabase instance that we register, we want to always create it using the instance of the DatabaseFactory that has already been registered, which again is accessible using the overload of .Use to get the Structuremap context. It's marked as .HttpContextScoped(), but I'm honestly not sure if that's required or not given that I'm using Structuremap.MVC5 nested containers.

For completeness, here is the DatabaseFactory:

public class DatabaseFactory
    private static NPoco.DatabaseFactory _internalFactory;

    public DatabaseFactory(FluentConfig fluentConfig)

    private static void Configure(FluentConfig fluentConfiguration)
        _internalFactory = NPoco.DatabaseFactory.Config(x =>
            x.UsingDatabase(() => new Database("ConnectionString"));

    public NPoco.Database GetDatabase()
        return _internalFactory.GetDatabase();

Learned so much about Vim that I should already know Sunday, 08 Mar, 2015

I've been a user of Vim for several years now. I use it as my go-to standard editor. As I primarily write C# code, I obviously use Visual Studio, a lot, and I have the wonderful VsVim extension installed, which provides a lot of the power of Vim, from within Visual Studio.

I thought I was pretty good at using Vim, until the other day when I saw Vim being used in some screencasts and I immediately thought that I suck at using Vim.

It turns out, that I learned enough about using Vim that got me a good increase in productivity, that I basically stopped learning how to use it. My brain must have decided that I learned all I needed to know to get me through my day, and stopped me wanting to learn anymore.

I have now found a great source of screencasts about using Vim, here, which are split into Beginner, Intermediate and Advanced. I learned how to do new stuff with Vim that is in the first beginner video.

I wish that I had found these videos several years ago when I was first starting out with Vim, as watching them then would probably have saved me a lot of time over the last several years.