Click here to Skip to main content
13,297,048 members (64,876 online)
Click here to Skip to main content
Add your own
alternative version


162 bookmarked
Posted 9 May 2010


, 27 May 2010
Rate this:
Please Sign up or sign in to vote.
A Visual Studio solution version converter to upgrade/downgrade solutions between VS versions.


SolutionConverter will convert a complete Visual Studio solution from one version to another; it allows you to convert your solutions to both older and newer versions. Currently, Visual Studio 2005, 2008, and 2010 are supported, including Visual C# Express and Visual Basic Express editions. Visual C++ project conversion is not yet supported.



I recently upgraded to Visual Studio 2010 at home and encountered the dreaded problem of opening my solutions in older Visual Studio versions. I attend H.I.T. where they have yet to install the new version, so I simply can't open my work on the institute's computers. After doing some research, I found this very nice article, but unfortunately, the application didn't support Visual Studio 2010 solutions when I started working on this project. Another thing I noticed that was missing was that it only changed the solution file and did not touch the project files, which also have to be edited for a smooth conversion.

So I decided to write my own tool with a view into the future, with simpler code which should allow easier extension in the future.

Looking through Google some more, this page popped up, explaining what exactly needed to be changed in the solution and project files to make the conversion work without any issues. I recommend going over it before continuing with the article to easily understand why the code is written the way it is.

Using the Code

This code will demonstrate the following:

  • Loading and analyzing a solution file. Detecting the version of Visual Studio it was intended for, and extracting the list of projects the solution contains.
  • Loading and analyzing the project files.
  • Converting the Solution file into the target version.
  • Working with the XML file, and converting the project files into the target version.

Loading the solution file and determining the solution version:

/// Retrieves the solution version from the file.
protected VisualStudioVersion GetSolutionVersion()
    VisualStudioVersion solVer = VisualStudioVersion.Unknown;
    TextReader reader = new StreamReader(this.solutionPath);
    string sln = reader.ReadToEnd();

    // Here we loop through the possible Visual Studio versions. 
    // Trying to determine the version of our solution.
    foreach (VisualStudioVersion version in Enum.GetValues(
        if (sln.Contains(version.GetStringValue()))
            solVer = version;

    return solVer;

VisualStudioVersion is an enum which represents the possible Visual Studio versions. The enum values use a custom attribute called StringValueAttribute, which allows an enum value to have a sort of 'ToString' method, GetStringValue(). GetStringValue() is a generic extension method which extracts the string value from the first StringValueAttribute occurrence on the specific enum value. To make it clearer, here is the enum definition:

/// Lists all possible solution versions.
public enum VisualStudioVersion
    /// Unknown Visual Studio version.
    /// Visual Studio 2002.
    [StringValue("Format Version 7.00")]
    VisualStudio2002 = 2002,
    /// Visual Studio 2003.
    [StringValue("Format Version 8.00")]
    VisualStudio2003 = 2003,
    /// Visual Studio 2005.
    [StringValue("Format Version 9.00")]
    VisualStudio2005 = 2005,
    /// Visual Studio 2008.
    [StringValue("Format Version 10.00")]
    VisualStudio2008 = 2008,
    /// Visual Studio 2010.
    [StringValue("Format Version 11.00")]
    VisualStudio2010 = 2010,

As you can see, the string values simply represent the values that will appear in the solution file. By simply checking which of these strings the solution file contains, we can determine the Visual Studio version.

In a similar fashion, we can determine the specific IDE the solution was created in, such as Visual Studio or some of the Express editions.

/// Gets the IDE version.
protected IdeVersion GetIdeVersion()
    IdeVersion ideVer = IdeVersion.Default;
    TextReader reader = new StreamReader(this.solutionPath);
    string sln = reader.ReadToEnd();

    // Here we loop through the possible Visual Studio versions. 
    // Trying to determine the IDE version.
    foreach (IdeVersion version in Enum.GetValues(typeof(IdeVersion)))
        if (sln.Contains(version.GetStringValue()))
            ideVer = version;
    return ideVer;

/// Lists all possible IDE versions.
public enum IdeVersion
    /// Using the default version or Unknown.
    /// The full Visual Studio version.
    [StringValue("Visual Studio")]
    /// C# Express Edition.
    [StringValue("Visual C# Express")]
    /// Visual Basic Express Edition.
    [StringValue("Visual Basic Express")]

Now that we know what the environment in which the solution was created in, we can continue and convert the solution into the target version in which the solution was created in.

public ConversionResult ConvertTo(VisualStudioVersion solutionVersion, IdeVersion ideVersion)

    bool success = true;
    StreamReader reader = new StreamReader(this.solutionPath);
    FileStream stream = null;
    TextWriter writer = null;
    string sln = reader.ReadToEnd();

    // Replace the solution version.
    sln = sln.Replace(this.VisualStudioVersion.GetStringValue(), 
    // If possible, also update the IDE version as well.
    if (ideVersion != IdeVersion.Default && this.IdeVersion != IdeVersion.Default)
        string oldVersion, newVersion;
        oldVersion = this.IdeVersion.GetStringValue() + " " + 
        newVersion = ideVersion.GetStringValue() + " " + 
        sln = sln.Replace(oldVersion, newVersion);
    // Now write the file back to the hard drive.
        stream = File.OpenWrite(this.solutionPath);
        writer = new StreamWriter(stream, Encoding.UTF8);
    catch (Exception)
        success = false;
        this.IsReady = false;
        if (stream != null)

It is that simple, in C#, to convert the solution from one version to another. Now, we also need to convert the projects. We use a Regex expression and a LINQ query to retrieve the path and filename of every project in the solution:

private void ConvertProjects(VisualStudioVersion solutionVersion)
    using (StreamReader reader = File.OpenText(this.solutionPath))
        List<string> projectStrings = new List<string>();
        IConverter projectConverter;
        string projectName, path;
        int index;

        // A bit messy, but gets the job done.
        // Retrieve the actual path of the solution.
        path = this.solutionPath.Remove(this.solutionPath.IndexOf(
        // Selects all the strings that contain the "Project("{xxxxxxxx
        //    -xxxx-xxxx-xxxx-xxxxxxxxxxxx}") = "Name", "Name\Name.xxproj","
        // signature.
           from Match match in this.projectPathRegex.Matches(reader.ReadToEnd())
           where match.Success
           select match.Value);

        // Here we attempt to convert all the projects
        // and save the conversion results.
        foreach (string projectString in projectStrings)
            // Cut string down to only contain the solution relative path.
            projectName = projectString.TrimEnd(new char[] { ' ', ',', '\"' });
            index = projectName.LastIndexOf('\"') + 1;
            projectName = path + projectName.Substring
            (index, projectName.Length - index);
            projectConverter = null;

            // Make sure we don't crash the program
            // by trying to convert a Visual C++ project
            if (!Path.GetExtension(projectName).Contains("vc"))
                projectConverter = new ProjectConverter(projectName);
                // Reserved for a Visual C++ Project converter here.

            if (projectConverter != null)

The code above creates a ProjectConverter object for each of the solution's projects, invokes the Convert method, and adds the conversion result to the ConversionResults collection.

Now we need to identify the project version we are working on. Since the solution file is a formatted text file, all we have to do is read it, replace the relevant values, and save it. Things change when working on project files. Project files in Visual Studio are XML files that contain all the relevant information and settings for the project. These files also rely on the XML namespace ''. There are four elements and attributes that we are going to need access to (as per this):

  • ToolsVersion attribute
  • ProductVersion element
  • TargetFrameworkVersion element
  • Project attribute of the Import element

Reading the information from the file and into the XElement and XAttribute objects:

public bool Reload()
        this.project = XDocument.Load(this.projectPath);
    catch (Exception)
        this.project = null;

    bool ret = false;
    this.vsVersion = VisualStudioVersion.Unknown;
    this.IsReady = false;
    if (this.project != null)
        this.toolsVersion = this.project.Root.Attribute(XName.Get("ToolsVersion"));
        this.productVersion = this.project.Root.Element(XName.Get("PropertyGroup", 
                              "ProductVersion", this.namespaceName));
        this.targetFrameworkVersion = this.project.Root.Element
                                     "TargetFrameworkVersion", this.namespaceName));
        this.importProject = this.project.Root.Element(XName.Get("Import", 
        this.Name = Path.GetFileNameWithoutExtension(this.projectPath);

        this.vsVersion = this.GetVsVersion();
        this.IsReady = true;
        ret = true;

    return ret;

Here is the code that we can use to determine which Visual Studio version this project belongs to:

/// Gets the Visual Studio version of the current project.
private VisualStudioVersion GetVsVersion()
    VisualStudioVersion vsVer = VisualStudioVersion.Unknown;

    double product;
    if (Double.TryParse(this.productVersion.Value, out product))
        if (product == 7)
            vsVer = VisualStudioVersion.VisualStudio2002;
        else if (product == 7.1)
            vsVer = VisualStudioVersion.VisualStudio2003;
        else if (product == 8)
            vsVer = VisualStudioVersion.VisualStudio2005;
        else if (product == 9)
            vsVer = VisualStudioVersion.VisualStudio2008;
        else if (product == 10)
            vsVer = VisualStudioVersion.VisualStudio2010;

    return vsVer;

And here is the code used to convert the projects. What we do is remove or add the relevant attributes or elements to the XML file, saving it afterwards. Since we are working directly with an XML object, we will receive a valid XML file after this procedure, ready to be used in a different Visual Studio version.

public ConversionResult ConvertTo(VisualStudioVersion vsVersion)
    // Calling the relevant method for editing
    // the attributes and elements of the XML.
    switch (vsVersion)
        case VisualStudioVersion.VisualStudio2002:
        case VisualStudioVersion.VisualStudio2003:
        case VisualStudioVersion.VisualStudio2005:
        case VisualStudioVersion.VisualStudio2008:
        case VisualStudioVersion.VisualStudio2010:

    // Saving the Project XML file.
    FileStream fileStream = null;
    XmlTextWriter writer = null;
    ret.ConverterReference = this;
        fileStream = new FileStream(this.projectPath, FileMode.Create);
        writer = new XmlTextWriter(fileStream, Encoding.UTF8);
        writer.Formatting = Formatting.Indented;
        ret.ConversionStatus = ConversionStatus.Succeeded;
    catch (Exception)
        ret.ConversionStatus = ConversionStatus.Failed;
        this.IsReady = false;
        if (writer != null)

    return ret;
/// Converts to VS2008 version.
private void ConvertToVs2008(VisualStudioVersion vsVersion)
    if (this.toolsVersion != null)
        double tools;
        if (Double.TryParse(this.toolsVersion.Value, out tools) && tools != 3.5)
            this.toolsVersion.Value = "3.5";
        this.project.Root.Add(new XAttribute(XName.Get("ToolsVersion"), "3.5"));

    if (this.productVersion != null)
        this.productVersion.Value = "9.0.21022";

    if (this.targetFrameworkVersion != null)
        double framework;
        if (Double.TryParse(
                   this.targetFrameworkVersion.Value.Length - 2),
                   out framework) && framework > 3.5)
            this.targetFrameworkVersion.Value = "v3.5";
        XElement newToolsVersion = new XElement(XName.Get("TargetFrameworkVersion", 
                                       this.namespaceName), "v2.0");

    if (this.importProject != null && 
        this.importProject.Value = 
          this.importProject.Value.Replace("$(MSBuildBinPath)", "$(MSBuildToolsPath)");

References and Inspirations


  • 6 May, 2010 - Version 1.0.3779.3862 - Initial release.
  • 9 May, 2010 - Updated source code (included DLL).
  • 27 May, 2010 - Updated article text.


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


About the Author

Arthur Liberman
Software Developer
Israel Israel
A 2nd year student majoring in Computer Science at Holon Institute of Technology.

You may also be interested in...

Comments and Discussions

AnswerWrong version for Visual Studio 2003 is 7.1, 2005 is 8, 2008 is 9 and 2010 is 10 Pin
Member 1247888430-Oct-16 2:13
memberMember 1247888430-Oct-16 2:13 
Questionneed convertion for vs2012/2013 to vs2010 Pin
Satish “శ్రీ” sri27-May-15 4:06
memberSatish “శ్రీ” sri27-May-15 4:06 
AnswerRe: need convertion for vs2012/2013 to vs2010 Pin
Member 1247888430-Oct-16 3:07
memberMember 1247888430-Oct-16 3:07 
Bugerror on converting Pin
Mohammed Shamsheer2-Apr-15 1:26
memberMohammed Shamsheer2-Apr-15 1:26 
Generalgood work Pin
po17252-Jul-13 6:22
memberpo17252-Jul-13 6:22 
GeneralRe: good work Pin
Arthur Liberman2-Jul-13 6:33
memberArthur Liberman2-Jul-13 6:33 
GeneralMy vote of 5 Pin
ravithejag17-Feb-13 18:07
memberravithejag17-Feb-13 18:07 
GeneralMy vote of 5 Pin
cjb11029-Jan-13 22:43
membercjb11029-Jan-13 22:43 
Nice tool with well explained code.
QuestionVS 2012 Pin
knoami10-Dec-12 6:37
memberknoami10-Dec-12 6:37 
QuestionIt works not well Pin
bubifengyun18-Sep-12 22:27
memberbubifengyun18-Sep-12 22:27 
AnswerRe: It works not well Pin
Arthur Liberman18-Sep-12 23:05
memberArthur Liberman18-Sep-12 23:05 
GeneralRe: It works not well Pin
bubifengyun19-Sep-12 19:11
memberbubifengyun19-Sep-12 19:11 
QuestionRegarding convertion of VS unmanaged C++ projects Pin
kartsam21-Aug-12 2:51
memberkartsam21-Aug-12 2:51 
AnswerRe: Regarding convertion of VS unmanaged C++ projects Pin
Arthur Liberman21-Aug-12 4:14
memberArthur Liberman21-Aug-12 4:14 
GeneralMy vote of 5 Pin
Sharjith10-Jul-12 9:47
memberSharjith10-Jul-12 9:47 
GeneralMy vote of 5 Pin
Jαved6-Jun-12 10:17
memberJαved6-Jun-12 10:17 
QuestionWill you implement Visual Studio 11 to Visual Studio 10 convert? Pin
FrewCen15-May-12 10:00
memberFrewCen15-May-12 10:00 
AnswerRe: Will you implement Visual Studio 11 to Visual Studio 10 convert? Pin
Member 1247888430-Oct-16 2:17
memberMember 1247888430-Oct-16 2:17 
QuestionNewer versions? Pin
Albert van Peppen11-Apr-12 1:41
memberAlbert van Peppen11-Apr-12 1:41 
QuestionThe type initializer for '<Module>' threw an exception. Pin
clover4leaves2-Feb-12 19:47
memberclover4leaves2-Feb-12 19:47 
AnswerRe: The type initializer for '' threw an exception. Pin
Arthur Liberman3-Feb-12 0:25
memberArthur Liberman3-Feb-12 0:25 
GeneralI'm not happy because I use c++ Pin
Martial Spirit31-Aug-11 19:26
memberMartial Spirit31-Aug-11 19:26 
GeneralRe: I'm not happy because I use c++ Pin
Arthur Liberman30-Dec-11 3:33
memberArthur Liberman30-Dec-11 3:33 
GeneralRe: I'm not happy because I use c++ Pin
Albert van Peppen11-Apr-12 1:43
memberAlbert van Peppen11-Apr-12 1:43 
GeneralRe: I'm not happy because I use c++ Pin
Alex Oren12-Dec-12 5:40
memberAlex Oren12-Dec-12 5:40 
BugBug Pin
wmq_whu15-Jul-11 20:20
memberwmq_whu15-Jul-11 20:20 
GeneralRe: Bug Pin
Arthur Liberman15-Jul-11 22:42
memberArthur Liberman15-Jul-11 22:42 
GeneralMy vote of 5 Pin
ipadilla17-May-11 9:20
memberipadilla17-May-11 9:20 
GeneralMy vote of 4 Pin
magicpapacy17-Jan-11 22:05
membermagicpapacy17-Jan-11 22:05 
GeneralRe: My vote of 4 Pin
SAKryukov9-May-11 16:35
memberSAKryukov9-May-11 16:35 
GeneralMy vote of 5 Pin
User97010-Aug-10 8:32
memberUser97010-Aug-10 8:32 
GeneralMy vote of 5 Pin
szcomma7-Jul-10 18:39
memberszcomma7-Jul-10 18:39 
GeneralSimply Awesome Pin
ChagantiSri15-Jun-10 0:17
memberChagantiSri15-Jun-10 0:17 
GeneralMy vote of 1 Pin
mheskol6-Jun-10 2:16
membermheskol6-Jun-10 2:16 
GeneralRe: My vote of 1 Pin
Arthur Liberman6-Jun-10 13:06
memberArthur Liberman6-Jun-10 13:06 
Generalconverting just the project file Pin
jpeterson26-May-10 11:12
memberjpeterson26-May-10 11:12 
GeneralRe: converting just the project file Pin
Arthur Liberman26-May-10 12:31
memberArthur Liberman26-May-10 12:31 
GeneralRe: converting just the project file Pin
Manish7930-May-10 23:38
memberManish7930-May-10 23:38 
GeneralRidiculous. Pin
Qwertie17-May-10 19:55
memberQwertie17-May-10 19:55 
GeneralThis is funny! Pin
Estys15-May-10 0:07
memberEstys15-May-10 0:07 
GeneralRe: This is funny! Pin
Arthur Liberman15-May-10 0:09
memberArthur Liberman15-May-10 0:09 
GeneralRe: This is funny! Pin
Estys15-May-10 0:47
memberEstys15-May-10 0:47 
GeneralIf u use SharpDevelop IDE you will not have to even think about this Pin
Cuchuk Sergey10-May-10 9:17
memberCuchuk Sergey10-May-10 9:17 
GeneralProject files should be writable Pin
PerlDev10-May-10 4:18
memberPerlDev10-May-10 4:18 
GeneralMono Pin
Daniel Fisher (lennybacon)10-May-10 2:42
memberDaniel Fisher (lennybacon)10-May-10 2:42 
GeneralRe: Mono Pin
Arthur Liberman10-May-10 4:16
memberArthur Liberman10-May-10 4:16 
GeneralRe: Mono Pin
Daniel Fisher (lennybacon)10-May-10 5:56
memberDaniel Fisher (lennybacon)10-May-10 5:56 
GeneralRe: Mono Pin
Paul Selormey10-May-10 15:47
memberPaul Selormey10-May-10 15:47 
GeneralGreate Pin
Khaniya9-May-10 20:32
memberKhaniya9-May-10 20:32 
GeneralProblems with the source code Pin
Marc Clifton9-May-10 13:30
protectorMarc Clifton9-May-10 13:30 

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 27 May 2010
Article Copyright 2010 by Arthur Liberman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid