public static bool SetProjectWorkingDir(object sol, string project_name, string working_dir)
        {
            bool made_change = false;

            Console.WriteLine("Looking for project {0}...", project_name);
            try
            {
                object prjs  = ViaCOM.GetProperty(sol, "Projects");
                object count = ViaCOM.GetProperty(prjs, "Count");
                for (int i = 1; i <= (int)count; ++i)
                {
                    object[] prjItemArgs = { (object)i };
                    object   prj         = ViaCOM.CallMethod(prjs, "Item", prjItemArgs);
                    string   name        = (string)ViaCOM.GetProperty(prj, "Name");
                    if (0 == string.Compare(name, project_name, ignore_case))
                    {
                        Console.WriteLine("Found project: {0}", project_name);
                        Console.WriteLine("Setting working directory");

                        string full_project_name = (string)ViaCOM.GetProperty(prj, "FullName");
                        Console.WriteLine(full_project_name);

                        // *NOTE:Mani Thanks to incompatibilities between different versions of the
                        // VCProjectEngine.dll assembly, we can't cast the objects recevied from the DTE to
                        // the VCProjectEngine types from a different version than the one built
                        // with. ie, VisualStudio.DTE.7.1 objects can't be converted in a project built
                        // in VS 8.0. To avoid this problem, we can use the com object interfaces directly,
                        // without the type casting. Its tedious code, but it seems to work.

                        // oCfgs should be assigned to a 'Project.Configurations' collection.
                        object oCfgs = ViaCOM.GetProperty(ViaCOM.GetProperty(prj, "Object"), "Configurations");

                        // oCount will be assigned to the number of configs present in oCfgs.
                        object oCount = ViaCOM.GetProperty(oCfgs, "Count");

                        for (int cfgIndex = 1; cfgIndex <= (int)oCount; ++cfgIndex)
                        {
                            object[] itemArgs       = { (object)cfgIndex };
                            object   oCfg           = ViaCOM.CallMethod(oCfgs, "Item", itemArgs);
                            object   oDebugSettings = ViaCOM.GetProperty(oCfg, "DebugSettings");
                            ViaCOM.SetProperty(oDebugSettings, "WorkingDirectory", (object)working_dir);
                        }

                        break;
                    }
                }
                made_change = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Failed to set working dir for project, {0}.", project_name);
            }

            return(made_change);
        }
        public static bool SetStartupProject(string startup_project)
        {
            bool result = false;

            try
            {
                // You need the 'unique name of the project to set StartupProjects.
                // find the project by generic name.
                Console.WriteLine("Trying to set \"{0}\" to the startup project", startup_project);
                object prjs  = ViaCOM.GetProperty(solution, "Projects");
                object count = ViaCOM.GetProperty(prjs, "Count");
                for (int i = 1; i <= (int)count; ++i)
                {
                    object[] itemArgs = { (object)i };
                    object   prj      = ViaCOM.CallMethod(prjs, "Item", itemArgs);
                    object   prjName  = ViaCOM.GetProperty(prj, "Name");
                    if (0 == string.Compare((string)prjName, startup_project, ignore_case))
                    {
                        object solBuild = ViaCOM.GetProperty(solution, "SolutionBuild");
                        ViaCOM.SetProperty(solBuild, "StartupProjects", ViaCOM.GetProperty(prj, "UniqueName"));
                        Console.WriteLine("  Success!");
                        result = true;
                        break;
                    }
                }

                if (result == false)
                {
                    Console.WriteLine("  Could not find project \"{0}\" in the solution.", startup_project);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("  Failed to set the startup project!");
                Console.WriteLine(e.Message);
            }
            return(result);
        }