Automatically Upgrading to Visual Studio 2010

I’ve had the need recently to convert a large number of projects from Visual Studio 2008 to Visual Studio 2010.  I was not able to find a tool out there that does this automatically, so I wrote one.  The key is to invoke devenv.exe from the command line and use the /upgrade switch.  Here is a link to the docs on that option.  And here is a Windows Forms app I wrote that searches for all Visual Studio solutions under a root directory and shells out to a command prompt to do the upgrade.

Of course, upgrading to VS 2010 is only half the process.  Usually you also want to re-target the application to .NET 4.  Just upgrading to VS 2010 will leave the application targeted to whatever version of .NET is was using (for VS 2008 it’s usually .NET 3.5).  Your help here is a macro you can install, which retargets all projects in the current solution.  What I could do is incorporate this code into my Upgrade Projects app. But alas I’m short on time and will have to defer this to a future date.

UPDATE: In the meantime, you can Add this macro to Visual Studio (Tools\Macros\Macros IDE, then select My Macros\Module1(:

Imports System.Runtime.Versioning
Imports VSLangProj

Public Module Module1

    ' macro to retarget all C#/VB projects in a solution to .NET Framework 4
 Sub SwitchFramework()
   Dim v40FrameworkName As FrameworkName = 
      New FrameworkName(".NETFramework", New Version(4, 0))

   For Each project As EnvDTE.Project In DTE.Solution.Projects
      If project.Kind = PrjKind.prjKindCSharpProject Then
           .Value = v40FrameworkName.FullName
      End If
 End Sub

End Module


Then go to Tools\Options\Environment\Keyboard, type SwitchFramework to locate the macro and assign it a shortcut, such as Ctrl+Shit+4.


You should now be able to press Ctrl+Shift+4 and the C# projects will re-target to .NET 4 – the full version. Cheers.

About Tony Sneed

Sr. Software Solutions Architect, Hilti Global Application Software
This entry was posted in Technical and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.