Click here to Skip to main content
13,298,551 members (51,533 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 12 Mar 2012

Upgrading VS 2008 projects to VS 2010 projects with PowerShell script

, 12 Mar 2012
Rate this:
Please Sign up or sign in to vote.
Power shell script for upgrading Visual Studio 2008 solutions and projects into Visual Studio 2010.


I have put together the Power shell script to upgrade solutions from Visual studio 2008 to Visual studio 2010. The script does it in few steps. Migrate the solution files, then the project, upgrade the target version then save the project file.

This is one of the first few scripts in powershell, if you feel some things can be done better, please let me know.


I recently had to migrate our codebase from Visual studio 2008 to Visual Studio 2010, then upgrade the target framework to .Net 4.0. Number of solutions is 100+, doing it manually one project at a time is very time consuming and honestly really boring. So this made me to try and automate most parts of this.

Using the code

The script consists of 2 sections:

1. Upgrade the solution

2. Modify the Target framework on the Project

Upgrade the solution

To upgrade the solution use the devenv.exe with /Upgrade command line switch.

Following is the power shell script that does it:

$sourcePath = 
$devenv = "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

$sourcePath -recurse -filter "*.sln" 
foreach ($i in $slnFiles)
Upgrade visual stdio solution to visual studio 2010
& $devenv $i.FullName 
Write-Host $i.FullName

The above script is run on all the sln files found in the input directory.

We have an alternate provision for upgrading the project files to visual studio 2010 using vcupgrade.exe. This would be available as part of Windows SDK 7. And helpful in case you like to perform the upgrade on the system which does not have visual studio installed. This tool comes with limitation that it can't convert solution files.

This script is using visual studio upgrade options and needs Visual studio 2010 installed on the machine its running on.

Modify the Project file

When we change the target framework from within visual studio these are the changes.

1. OldTargetFramework tag

2. <span class="TextRun SCX200877060" xml:lang="EN-US">TargetFrameworkVersion</span>

3. ToolsVersion

4. Project element

Following power shell scripts can take care of this:

<pre>$sourcePath = "D:\MigTest\Src"

# if TargetFrameworkVersion is not already 4.0
if($toolsVersion.Value -ne "4.0")
    # Upgrade Project / ToolsVersion="4.0"
    $toolsVersion.Value = "4.0"
 $isProjectXmlUpdated = $true
# if TargetFrameworkVersion is not already 4.0
# Upgrade TargetFrameworkVersion "v4.0"
$targetFrameworkElements = $projectGroup.GetElementsByTagName("TargetFrameworkVersion")
$oldToolsVersion = "v3.5"
foreach($targetFrameworkElement in $targetFrameworkElements)
    $oldToolsVersion = $targetFrameworkElement.InnerText
    $targetFrameworkElement.InnerText = "v4.0"
    $isProjectXmlUpdated = $true

# Update OldToolsVersion from TargetFrameworkVersion
$oldToolsVersionElements = $projectGroup.GetElementsByTagName("OldToolsVersion")
if($oldToolsVersionElements -ne $null -and $oldToolsVersionElements.Count -gt 0)
    foreach($oldToolsVersionElement in $oldToolsVersionElements)
        $oldToolsVersionElement.InnerText = $oldToolsVersion
  $isProjectXmlUpdated = $true

</pre><h2>Points of Interest</h2>

Execution Policy

When you try to run the above script, you will end up in access violation, the current script execution policy wont allow execution of the scripts. You can check the current execution policy using Get-ExecutionPolicy command. You need to update the execution policy to allow the script to run, Set-ExecutionPolicy to Unrestricted if you fully trust the script you are running. You should set the earlier execution policy once you are done with the script.

Starting process

We can start a process using Start-Process command let or by using Start-Job or simply by invoking the .exe directly. Each one of these have its own advantages.

Launching an exe as below, power shell console starts this process and continues with the next command, it wont wait for the response. In case of this script, even after the migration activity show its complete. Some of the devenv processing could still potentially be running in the background. Once all the devenv process are completed only then the upgrade is complete.

$devenv = "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" 
&$devenv $fileName /Upgrade<code style="font-family: Calibri,sans-serif; font-size: 11pt;">  

The other alternate is to use Start-Proces command let which has an option to wait for the completion of the process.

$args = '$fileName /Upgrade' 
Start-Process $devenv $args -Wait  

XML Formatting

Once the project file is updated with Target framework and other xml elements, we need to write it back to the project file. the xml file not formatted anymore. To preserver or apply the prefered formatting we can use XmlTextWriter with correct Formatting and Indentation option.

    $StringWriter = New-Object System.IO.StringWriter 
    $XmlWriter = 
New-Object System.XMl.XmlTextWriter $StringWriter 
= "indented" 
    $xmlWriter.Indentation = $Indent 
    Write-Output $StringWriter.ToString() 

Further Updates

I am planning to updated the scripts with the following:

  • Use configuration file for inputs to the script such as folder for conversion, location of the Visual studio 2010.
  • Report for the upgrade in text or html format


Windows PowerShell Quick Reference

Microsoft Script Cente

Windows PowerShell Cheat Sheet


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vivek Krishnamurthy
India India
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionNot an article Pin
Mark Nischalke12-Mar-12 3:02
mvpMark Nischalke12-Mar-12 3:02 
AnswerRe: Not an article Pin
Vivek Krishnamurthy13-Mar-12 17:55
memberVivek Krishnamurthy13-Mar-12 17:55 
QuestionVS 2080 Pin
Ajay Vijayvargiya11-Mar-12 19:26
memberAjay Vijayvargiya11-Mar-12 19:26 
AnswerRe: VS 2080 Pin
Vivek Krishnamurthy11-Mar-12 19:52
memberVivek Krishnamurthy11-Mar-12 19:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 12 Mar 2012
Article Copyright 2012 by Vivek Krishnamurthy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid