Export (0) Print
Expand All

How to: Publish Multiple Projects in a Solution 

A solution can contain several projects, but ClickOnce deployment is constrained in that it can only publish one project at a time. For solutions with many projects, publishing them one by one can be burdensome. This procedure shows how to automate the process using a macro to publish all the projects in a solution.

To create the publishing macro

  1. Open the Macro Explorer. From the Tools menu, click Macros, then Macro Explorer.

  2. Create a new macro module. In the Macro Explorer, select the MyMacros node. From the Tools menu, click Macros, then New Macro Module. Name the module PublishAllProjects.

  3. In the Macro Explorer, open the MyMacros node, then open the PublishAllProjects module by double-clicking it (or from the Tools menu, click Macros, then Macros IDE).

  4. In the Macros IDE, add the following code to the module, after the Import statements:

    Public Module PublishAllProjects
        Sub PublishAllProjectsInSolution()
            ' Before using this macro, the certficate and security zone must be set.
            ' You can do this by publishing the projects using the VS IDE.
            Dim slnbld2 As SolutionBuild2 = CType(DTE.Solution.SolutionBuild, SolutionBuild2)
            'Save changes to all projects and clean.
            For Each proj As Project In DTE.Solution.Projects
            For Each proj As Project In DTE.Solution.Projects
                'Verify project is a windows application or console application before continuing
                Dim outputType As Integer = proj.Properties.Item("OutputType").Value
                If outputType <> 0 AndAlso outputType <> 1 Then
                    Continue For
                End If
                'GenerateManifests and SignManifests must always to true for publishing to work. 
                proj.Properties.Item("GenerateManifests").Value = True
                proj.Properties.Item("SignManifests").Value = True
                slnbld2.BuildProject(proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, proj.UniqueName, True)
                'only publish if build was successful.
                If slnbld2.LastBuildInfo <> 0 Then
                    MsgBox("Build failed for " & proj.UniqueName)
                    slnbld2.PublishProject(proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, proj.UniqueName, True)
                    If slnbld2.LastPublishInfo = 0 Then
                        MsgBox("Publish succeeded for " & proj.UniqueName)
                        MsgBox("Publish failed for " & proj.UniqueName)
                    End If
                End If
        End Sub
    End Module
  5. Close the Macros IDE. The focus will return to Visual Studio.

To publish all projects in a solution

  1. Create a Visual Basic Windows Application project. From the File menu, click New, then Project.

  2. In the New Project dialog box, select Windows Application from the Visual Basic node. Name the project MultiProj.

  3. Add two more Windows Application projects to the MultiProj solution. Name them Proj1 and Proj2.

  4. Publish each of the projects in the solution first. The macro requires that the ClickOnce manifests be signed and the security zone be set for each of the projects. By publishing each using the integrated development environment (IDE) before using the macro, the publish process will sign the ClickOnce manifests and set the security zone, which are necessary for the macro to run.

    In Solution Explorer, select MultiProj. From the Project menu, select Properties. In the Project Designer, click the Publish tab. On the Publish page, specify a publishing location of publish\, then click Publish Now.

    Repeat this for the other projects in the solution.

  5. Publish MultiProj again by invoking the macro in the Visual Studio command window. To view the Command window, from the View menu, click Other Windows, then Command Window, or press CTRL+ALT+A. In the Command Window, type macros; auto-complete will provide a list of available macros. Select the following macro and press Enter:


  6. When the publish process for each project succeeds, you will get a message saying "Publish succeeded for MultiProj\MultiProj.vbproj." Click OK on each message box.

  7. Look in the publish subdirectories in each project directory. You should see the manifests, setup.exe, and publish Web page files.

See Also

Community Additions

© 2014 Microsoft