Skip to content

Instantly share code, notes, and snippets.

@kevinmcmahon
Created May 6, 2010 07:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinmcmahon/391885 to your computer and use it in GitHub Desktop.
Save kevinmcmahon/391885 to your computer and use it in GitHub Desktop.
[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | Out-Null
#specify the root of your source tree below
$path = "C:\Code\chatsworth"
$ns = "http://schemas.microsoft.com/developer/msbuild/2003"
$xname = [System.Xml.Linq.XName]::Get("PropertyGroup",$ns)
$tfname = [System.Xml.Linq.XName]::Get("TargetFrameworkVersion",$ns)
$xws = New-Object System.Xml.XmlWriterSettings
$xws.OmitXmlDeclaration = $true
$xws.Indent = $true
function updatefx($filename)
{
#Write-Host $filename
$xml = [System.Xml.Linq.XDocument]::Load($filename)
$result = $xml.Descendants($xname)
foreach ($i in $result)
{
$fxelem = $i.Element($tfname)
if($fxelem)
{
$i.SetElementValue($tfname,"v4.0")
}
}
$xw = [System.Xml.XmlWriter]::Create($filename, $xws)
$xml.Save($xw)
$xw.Close()
}
$csprojs = Get-ChildItem $path *.csproj -Recurse
foreach ($file in $csprojs)
{
updatefx $file.FullName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment