Fixing Visual Studio 2008 BETA 1 solution files

Andrew Arnott (found via the “This Week on Channel 9″ show) wrote in one of his latest posts about the problem that certain Visual Studio solution files won’t open if they are double clicked. What happens when you click a solution file? Internally an application is launched that inspects the solution file and depening on what is found in the header the corresponding Visual Studio is launched (if installed on the system).

The Visual Studio 2008 BETA (aka. Orcas) created an entry into the header that looks like this: “# Visual Studio Codename Orcas”. When the version selector (that’s the name of the application that inspects the solution file) inspects the file it finds this tag and doesn’t know what to do because the VS 2008 BETA might no longer be on your system. Nothing happens.

Andrew’s solution to fix this problem is to open the solution file and change the “# Visual Studio Codename Orcas” to “# Visual Studio 2008″. Now, what if you have more than one of these files lying around?

Well, the user staceyw created a simple PowerShell script (a one liner - very impressive!) that inspects the solution files and alters the header to make them work with Visual Studio 2008:

dir . -r *.sln | %{$t=cat $_.fullname;$t -replace “Codename Orcas”,”2008″ > $_}

But what if you don’t have PowerShell and you don’t want to install it? I have created a short C# console application that does exactly the same as the PowerShell script; it’s a lot more in code but you don’t need to install the PowerShell ;)

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(“SolutionFix v” + Assembly.GetExecutingAssembly().GetName().Version.ToString());
        Console.WriteLine(“Copyright 2008 Christian Liensberger”);
        Console.WriteLine(“====================================\r\n);

        // check if all arguments required have been given.
        if (args.Length == 0)
        {
            // print the usage to the screen.
            Console.WriteLine(“USAGE:”);
            Console.WriteLine(string.Format(“{0} <Path>; example: {0} C:\\,
                Path.GetFileName(Assembly.GetExecutingAssembly().Location)));
            return;
        }

        string[] files = null;
        try
        {
            // get all files for the given directory and sub-directories.
            files = Directory.GetFiles(args[0], “*.sln”, SearchOption.AllDirectories);
            Console.WriteLine(files.Length + ” solution file(s) found.\r\n);
        }
        catch (Exception ex)
        {
            Console.WriteLine(“Error while searching for files: “ + ex.Message);
            return;
        }

        // loop over the results.
        foreach (var file in files)
        {
            Console.WriteLine(“Processing: “ + file);

            try
            {
                // read all the lines of the file and check if we can use it.
                var lines = File.ReadAllLines(file);
                if (lines.Length < 3)
                    continue;

                // understand if a fix is required.
                var version = lines[2];
                if (version == “# Visual Studio Codename Orcas”)
                {
                    Console.Write(“Solution file needs to be fixed…”);
                    // apply the fix.
                    lines[2] = “# Visual Studio 2008″;

                    // create a backup copy of the solution file.
                    File.Copy(file, file + “.bak”);
                    // write the fixed file to the given location.
                    File.WriteAllLines(file, lines);

                    Console.WriteLine(” done!”);
                }
                else
                {
                    Console.WriteLine(“Solution file doesn’t need to be fixed.”);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(“Error while processing file: “ + ex.Message);
            }
        }
    }
}

Download the compiled version from here.

Published on Feb 16th, 2008 — Tags: ,
   digg it!    kick it   

1 Comment ( Comments RSS TrackBack )

  1. The PS script is buggy. It needs to be

    dir . -r *.sln | %{$t=cat $_.fullname;$t -replace “Codename Orcas”,”2008? > $_.fullname}

    Comment by Christian Geuer-Pollmann — June 13, 2008 @ 9:41 am

Leave a comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> [code][/code] [code lang="csharp"][/code].