IExtendable while (this.IsAlive) self => self.UpdateAll()

2Nov/120

IlMerge in TeamCity

I wanted to IlMerge an assembly in a TeamCity project. TeamCity has a Powershell build step that you can use to run your own arbitrary scripts. Here’s how I did it

TeamCity Configuration

image

Powershell Script

15Aug/120

Install-VSCommandPrompt Powershell Script updated

Tagged as: No Comments
20Sep/110

VS Powershell Session

Add this script to your powershell profile.  If you don't know where your powershell profile is, open a powershell session and type $profile and press <Enter>.  In Windows 7, you can run powershell from the current folder by typing powershell in the address bar of windows explorer.

	#Set environment variables for Visual Studio Command Prompt
	$vspath = (get-childitem env:VS100COMNTOOLS).Value
	$vsbatchfile = "vsvars32.bat";
	$vsfullpath = [System.IO.Path]::Combine($vspath, $vsbatchfile);

	#$_ shortcut represents arguments
	pushd $vspath
	cmd /c $vsfullpath + "&set" |
	foreach {
	  if ($_ -match “=”) {
		$v = $_.split(“=”);
		set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])"
	  }
	}
	popd
	write-host "Visual Studio 2010 Command Prompt variables set." -ForegroundColor Red
Tagged as: No Comments
5Jul/110

Installing all NuGet Packages in the Solution

The benefits of using NuGet to manage your project dependencies should be well-known by now.

If not, read this.

There’s one area where NuGet is still somewhat deficient: Team Workflow.

Ideally, when you begin work on a new solution, you should follow these steps:

1) Get the latest version of the source code.

2) Run a command to install any dependent packages.

3) Build!

It’s step 2 in this process that is causing some trouble. NuGet does offer a command to install packages for a single project, but the developer is required to run this command for each project that has package references. It would be nice if NuGet would install all packages for all projects using packages/repositories.config, but at the time of this writing it will not. However, it is fairly easy to add a powershell function to the NuGet package manager console that will do this for you.

First, you should download the NuGet executable and add its directory to your PATH Environment variable. I placed mine in C:devutilsNuGet<version>. You’ll need to be able to access the executable from the command-line.

Second, you need to identify the expected location of the NuGet Powershell profile. You can do this be launching Visual Studio, opening the Package Manager Console, type $profile, then press enter. The console will show you the expected profile path. In Windows 7 it will probably be: “C:Users<user>DocumentsWindowsPowerShellNuGet_profile.ps1”

Next you need to create a file with that name in that directory.

Next, paste the following powershell code into the file:

function Install-NuGetPackagesForSolution()
{
    write-host "Installing packages for the following projects:"
    $projects = get-project -all
    $projects
   
    foreach($project in $projects)
    {
        Install-NuGetPackagesForProject($project)
    }

}

function Install-NuGetPackagesForProject($project)
{
    if ($project -eq $null)
    {
        write-host "Project is required."
        return
    }

    $projectName = $project.ProjectName;
    write-host "Checking packages for project $projectName"
    write-host ""
   
    $projectPath = $project.FullName
    $projectPath
   
    $dir = [System.IO.Path]::GetDirectoryName($projectPath)
    $packagesConfigFileName = [System.IO.Path]::Combine($dir, "packages.config")
    $hasPackagesConfig = [System.IO.File]::Exists($packagesConfigFileName)
   
    if ($hasPackagesConfig -eq $true)
    {
        write-host "Installing packages for $projectName using $packagesConfigFileName."
        nuget i $packagesConfigFileName -o ./packages
    }

}

Restart Visual Studio 2010. After the package manager console loads, you should be able to run the Install-NuGetPackagesForSolution command. The command will iterate over each of your projects, check to see if the project contains a packages.config file, and if so run NuGet install against the packages.config.

You may also wish to do this from the PowerShell console outside of visual studio. If you are in the solution root directoy you can run the following two commands:

$files = gci -Filter packages.config -Recurse
$files | ForEach-Object {nuget i $_.FullName -o .packages}