Damian Hickey

Mostly software and .NET related. Mostly.

PSake task to scan and execute all test projects

Another one for the toolbox. This script will execute all scan for all unit test projects and execute them. It assumes that all test project names end with 'Tests', the assembly name is the same as project name, and the project folder is at the solution root.

 

task RunTests -depends Compile {
	$xunitRunner = "tools\XUnitRunner\xunit.console.clr4.exe"
        $project = $_.BaseName
        Get-ChildItem ..\ -Recurse -Include *Tests.csproj | % {
		   .$xunitRunner "$srcDir\$project\bin\Release\$project.dll"
	}
}

 

Simple Powershell script to tidy NuGet's packages.config

This:

param([string]$path = ".")

$packagesConfigFiles = Get-ChildItem $path -Recurse | Where-Object {$_.Name -eq "packages.config"}

if($packagesConfigFiles -eq $null){
	Write-Error "No packages found"
	return
}

foreach($packagesConfig in $packagesConfigFiles){
	Write-Host "Tidying" $packagesConfig.FullName
	$xml = [xml](Get-Content $packagesConfig.FullName)
	$sortedNodes = $xml.packages | select-xml 'package' | Select-Object -expand Node | sort 'id'

	[xml]$sortedXml = "<?xml version='1.0' encoding='utf-8'?>
	<packages>
		$($sortedNodes | % { $_.OuterXml})
	</packages>"

	$sortedXml.Save($packagesConfig.FullName)
}

...will turn this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Iesi.Collections" version="3.1.0.4000" />
  <package id="NHibernate" version="3.1.0.4000" />
  <package id="Castle.Core" version="2.5.2" />
  <package id="NHibernate.Castle" version="3.1.0.4000" />
  <package id="FluentNHibernate" version="1.2.0.712" />
  <package id="Microsoft.IdentityModel" version="6.1.7600" />
  <package id="NBuilder" version="2.3.0.0" />
  <package id="FluentMigrator" version="0.9.0.1" />
  <package id="Ninject" version="2.2.1.0" />
  <package id="Ninject.Extensions.Wcf" version="2.2.0.0" />
  <package id="Ninject.Web.Mvc2" version="2.2.0.1" />
  <package id="Common.Logging" version="1.2.0" />
  <package id="Rx-Core" version="1.0.2856.0" />
  <package id="Compare-NET-Objects" version="1.0.2.0" />
  <package id="StoryQ" version="2.0.5" />
  <package id="Moq" version="4.0.10827" />
  <package id="xunit" version="1.8.0.1545" />
  <package id="xunit.extensions" version="1.8.0.1545" />
</packages>

...into this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Castle.Core" version="2.5.2" />
  <package id="Common.Logging" version="1.2.0" />
  <package id="Compare-NET-Objects" version="1.0.2.0" />
  <package id="FluentMigrator" version="0.9.0.1" />
  <package id="FluentNHibernate" version="1.2.0.712" />
  <package id="Iesi.Collections" version="3.1.0.4000" />
  <package id="Microsoft.IdentityModel" version="6.1.7600" />
  <package id="Moq" version="4.0.10827" />
  <package id="NBuilder" version="2.3.0.0" />
  <package id="NHibernate" version="3.1.0.4000" />
  <package id="NHibernate.Castle" version="3.1.0.4000" />
  <package id="Ninject" version="2.2.1.0" />
  <package id="Ninject.Extensions.Wcf" version="2.2.0.0" />
  <package id="Ninject.Web.Mvc2" version="2.2.0.1" />
  <package id="Rx-Core" version="1.0.2856.0" />
  <package id="StoryQ" version="2.0.5" />
  <package id="xunit" version="1.8.0.1545" />
  <package id="xunit.extensions" version="1.8.0.1545" />
</packages>

To be honest, I'd prefer if NuGet did this itself.

Signing Mercurial Changesets on Windows

Unfortunately, cryptographic signing of changesets is not a first class citizen in the Mercurial world. Signing of changesets at commit time requires the use of the commitsigs extension. This is how to set it up on windows x64.

Install

  1. Download and install Gpg4win from http://www.gpg4win.org/. Launch
  2. Create a key pair.

Installing commitsigs Extension

  1. Download commitsigs.py and save to desired location. I used %ProgramFiles%\TortoiseHg\extensions
  2. Open your mecurial.ini settings file located at %USERPROFILE%\mercurial.ini
  3. Under the [extensions] add property with path to commitsigs.py

    commitsigs = C:\Program Files\TortoiseHg\extensions\commitsigs.py

  4. Add a [commitsigs] section with the following properties:

    [commitsigs]
    scheme = gnupg
    gnupg.path = C:\Program Files (x86)\GNU\GnuPG\gpg2.exe
    gnupg.flags = --local-user <emailaddress>

    where <emailaddress> is the value you provided when creating your private key.

Your mercurial.ini should look something like this:

Testing

Check the plugin is found by mercurial by entering 'hg help commitsigs'. You should see the help output:

Signing commits

When you commit, you will be prompted for your the passphrase for the key you created. If you have pgp-agent.exe running in the background, this will happen once per windows session:

Verifying signatures

Check the changeset signature by issuing 'hg verifysigs':

The signature is part of the changeset and can be visible via 'hg log --debug':