Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

VS2010 need help programatically adding x64 platforms to existing C++ solutions

$
0
0

This is proving to be more difficult than I expected.

My original plan was to record a macro in VS2010 that recorded me manually adding in the x64 platform.  Then I was going to call devenv.exe to execute the macro (passing the full *.sln path).  But there are limitations as to what can be recorded in a macro.

I'm not familiar with VBA, so I started looking into writing a program in C#.

This is also the first time I've looked into any of this extensibility.

NOTE: none of our solutions currently have x64 platforms in them.  Some only have a "Release" config. (as the 'debug' ones were deleted).  Though there are some solutions do have have 'release' and 'debug' configs.)

Goal: to have console app (or macro) that will process a directory of C++ *.sln solutions and add in the x64 platforms *as if it had been done manually*, leaving the Active configuration at "release|Win32".

I have the "Visual Studio 2005 SDK" installed but have not found it to be of any use, e.g. "BscPrj.sln".

I'm sort of surprised there isn't a complete solution posted anywhere that does this...

This is what I have so far, but doesn't work and I'm stuck. I would appreciate any assistance on this.

class Program
{
 static void Main(string[] args)
     {
     List<string> solutionsToProcess = new List<string>();

    // TODO: call a method to populate solutionsToProcess
    // with full path of *.sln files, e.g.:   c:\temp\MyProgram\MyProgram.sln

     EnvDTE80.DTE2 dte;
     object obj = null;
     System.Type t = null;

     t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true);

     // Attempt to create an instance of envDTE. 
     obj = System.Activator.CreateInstance(t, true);

     // Cast to DTE2.
     dte = (EnvDTE80.DTE2)obj;

    // Get a reference to the solution2 object.
    Solution2 soln = (Solution2)dte.Solution;

    for (int sidx = 0; sidx < solutionsToProcess.Count; sidx++)
     {
      soln.Open(solutionsToProcess[sidx]);
      SolutionBuild2 sb = (SolutionBuild2)soln.SolutionBuild;
      SolutionConfigurations scg = sb.SolutionConfigurations;
      bool x64Exists = false;

      try
         {
	      foreach (SolutionConfiguration config in scg)
          {
              Trace.WriteLine(config.Name);
              foreach (SolutionContext context in config.SolutionContexts)
              {
               Trace.WriteLine(String.Format("{0} - {1}|{2} - Build: {3}, Deploy: {4} Collection Count: {5}",
                          context.ProjectName,
                          context.ConfigurationName,
                          context.PlatformName,
                          context.ShouldBuild,
                          context.ShouldDeploy,
                          context.Collection.Count.ToString()));

                if (context.ConfigurationName.CompareTo("Release") == 0 &&
                              context.PlatformName.CompareTo("x64") == 0)
                    {
                        x64Exists = true;
                        break;
                     }
                }
               }

             if (!x64Exists)
                 {
                 Trace.WriteLine("*  Add code here to create x64 platform debug & release *");
                 }
            }
      catch (Exception ex)
          {
            Trace.WriteLine(ex.Message);
          }
      finally
          {
           // soln.Close(true);
              soln.Close(false);
          }
       }
    }
}



Viewing all articles
Browse latest Browse all 4410

Trending Articles