title: Programmatically publish web application
body: <p>I'm trying to write a visual studio extension that allows me to publish multiple web applications in a solution, similar to using the one-click publish feature on all the projects.</p>
  
  <pre><code>DTE2 service = (DTE2)this.GetService(typeof(DTE));
  Projects projects = service.Solution.Projects;
  SolutionBuild2 build = (SolutionBuild2)service.Solution.SolutionBuild;
  
  foreach (Project project in projects)
  {
     build.PublishProject("Release", project.UniqueName, true);
  }
  </code></pre>
  
  <p>When I try to run this code, the only result in the output window is this:</p>
  
  <pre><code>Error: Object reference not set to an instance of an object.
  ========== Publish: 0 succeeded, 0 failed, 0 skipped ==========
  </code></pre>
  
  <p>... which doesn't tell me much.  Is there a way to find out what's going wrong?</p>
  
  <p>I also see there an interface <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivspublishableprojectcfg%28v=VS.100%29.aspx" rel="nofollow">IVsPublishableProjectCfg</a>, but there doesn't seem to be any examples of how to use it.</p>
  
  <p>Is there another way to programmatically publish web applications to a certain directory, similar to how the one-click publish feature works?</p>