title: Visual studio 2008 macro to get source code
body: <p>I have a macro that opens a solution, connects to SourceSafe and downloads the latest version of each file inside the solution. To this point all works correctly.</p>
  
  <p>Now I want to execute devenv.exe with /command option to run this macro and close the Visual Studio environment once the source code is downloaded, and at this point I’m having some problems:</p>
  
  <p>If I use a macro like the one following these lines, Visual Studio starts, loads the solution, starts getting source code and then exits without waiting for the code to be completely downloaded.</p>
  
  <pre><code>DTE.Solution.Open("C:\ApeironDev\Soluciones\SolucioApeiron\SolucioApeiron.sln")
  DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
  DTE.ActiveWindow.Object.GetItem("SolucioApeiron").Select(vsUISelectionType.vsUISelectionTypeSelect)
  DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.ContextGetLatestVersion")
  DTE.ExecuteCommand("File.Exit")
  </code></pre>
  
  <p>If I add a line to Sleep the macro for some time, say 20 minutes, this crashes with an error regarding error in COM call (I know, this is not an elegant way to do the job, but in order to test…).</p>
  
  <pre><code>DTE.Solution.Open("C:\ApeironDev\Soluciones\SolucioApeiron\SolucioApeiron.sln")
  DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
  DTE.ActiveWindow.Object.GetItem("SolucioApeiron").Select(vsUISelectionType.vsUISelectionTypeSelect)
  DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.ContextGetLatestVersion")
  Threading.Thread.Sleep(New System.TimeSpan(0, 20, 0))
  DTE.ExecuteCommand("File.Exit")
  </code></pre>
  
  <p>What I’m searching for is a way to start Visual Studio, load a solution, get the latest version of the source code (waiting for the process to finish) and then close the Visual Studio environment.
  Any help?</p>
  
  <p>Clarification, To run the macro I use the following command line:</p>
  
  <pre><code>devenv.exe /command "Macros.MyMacros.SourceControl.GetLastVersion"
  </code></pre>
  
  <p>Where <strong><em>Macros.MyMacros.SourceControl.GetLastVersion</em></strong> is the complete path to the macro containing the code above described.</p>