Thursday, 23 July 2009

Updating assembly versions in Visual Studio project files

Sometimes you need to update all the references to a particular assembly so that they use a newer version than the original one that was added to the project.

One option is to manually edit the references for each project, removing and re-adding the assembly.

Option two, which is a bit nicer, is to use something like this PowerShell script:

Get-ChildItem -recurse -filter "*.*proj" | Foreach-Object { (Get-Content $_.FullName) | Foreach-Object { $_ -replace "", "" } | Set-Content $_.FullName }

In this example, we are replacing instances of "" with "" – handy if you just happened to be upgrading to the latest version of Castle.

Note the use of the parentheses () around the Get-Content - without those you'll end up with an Access Denied error as it will be trying to write to the same file it is reading from.

No comments: