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
Open the Macro Explorer. From the Tools menu, click Macros, then Macro Explorer.
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.
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).
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 proj.Save() Next slnbld2.Clean(True) 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 proj.Save() 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) Else slnbld2.PublishProject(proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, proj.UniqueName, True) If slnbld2.LastPublishInfo = 0 Then MsgBox("Publish succeeded for " & proj.UniqueName) Else MsgBox("Publish failed for " & proj.UniqueName) End If End If Next End Sub End Module
Close the Macros IDE. The focus will return to Visual Studio.
To publish all projects in a solution
Create a Visual Basic Windows Application project. On the File menu, click New Project.
In the New Project dialog box, select Windows Application from the Visual Basic node. Name the project MultiProj.
Add two more Windows Application projects to the MultiProj solution. Name them Proj1 and Proj2.
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.
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:
Macros.MyMacros.PublishAllProjects.PublishAllProjectsInSolution
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.
Look in the publish subdirectories in each project directory. You should see the manifests, setup.exe, and publish Web page files.
See Also
Tasks
How to: Edit and Programmatically Create Macros
How to: Publish a Project That Has a Specific Locale
Reference
Concepts
Publishing ClickOnce Applications