Building ClickOnce Applications from the Command Line - Visual Studio 2015 (original) (raw)


Share via


Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

In Visual Studio, you can build projects from the command line, even if they are created in the integrated development environment (IDE). In fact, you can rebuild a project created with Visual Studio on another computer that has only the .NET Framework installed. This allows you to reproduce a build using an automated process, for example, in a central build lab or using advanced scripting techniques beyond the scope of building the project itself.

Using MSBuild to Reproduce ClickOnce Application Deployments

When you invoke msbuild /target:publish at the command line, it tells the MSBuild system to build the project and create a ClickOnce application in the publish folder. This is equivalent to selecting the Publish command in the IDE.

This command executes msbuild.exe, which is on the path in the Visual Studio command-prompt environment.

A "target" is an indicator to MSBuild on how to process the command. The key targets are the "build" target and the "publish" target. The build target is the equivalent to selecting the Build command (or pressing F5) in the IDE. If you only want to build your project, you can achieve that by typing msbuild. This command works because the build target is the default target for all projects generated by Visual Studio. This means you do not explicitly need to specify the build target. Therefore, typing msbuild is the same operation as typing msbuild /target:build.

The /target:publish command tells MSBuild to invoke the publish target. The publish target depends on the build target. This means that the publish operation is a superset of the build operation. For example, if you made a change to one of your Visual Basic or C# source files, the corresponding assembly would automatically be rebuilt by the publish operation.

For information on generating a full ClickOnce deployment using the Mage.exe command-line tool to create your ClickOnce manifest, see Walkthrough: Manually Deploying a ClickOnce Application.

Creating and Building a Basic ClickOnce Application Using MSBuild

To create and publish a ClickOnce project

  1. Click New Project from the File menu. The New Project dialog box appears.
  2. Select Windows Application and name it CmdLineDemo.
  3. From the Build menu, click the Publish command.
    This step ensures that the project is properly configured to produce a ClickOnce application deployment.
    The Publish Wizard appears.
  4. In the Publish Wizard, click Finish.
    Visual Studio generates and displays the default Web page, called Publish.htm.
  5. Save your project, and make note of the folder location in which it is stored.
    The steps above create a ClickOnce project which has been published for the first time. Now you can reproduce the build outside of the IDE.

To reproduce the build from the command line

  1. Exit Visual Studio.
  2. From the Windows Start menu, click All Programs, then Microsoft Visual Studio, then Visual Studio Tools, then Visual Studio Command Prompt. This should open a command prompt in the root folder of the current user.
  3. In the Visual Studio Command Prompt, change the current directory to the location of the project you just built above. For example, type chdir My Documents\Visual Studio\Projects\CmdLineDemo.
  4. To remove the existing files produced in "To create and publish a ClickOnce project," type rmdir /s publish.
    This step is optional, but it ensures that the new files were all produced by the command-line build.
  5. Type msbuild /target:publish.
    The above steps will produce a full ClickOnce application deployment in a subfolder of your project named Publish. CmdLineDemo.application is the ClickOnce deployment manifest. The folder CmdLineDemo_1.0.0.0 contains the files CmdLineDemo.exe and CmdLineDemo.exe.manifest, the ClickOnce application manifest. Setup.exe is the bootstrapper, which by default is configured to install the .NET Framework. The DotNetFX folder contains the redistributables for the .NET Framework. This is the entire set of files you need to deploy your application over the Web or via UNC or CD/DVD.

Publishing Properties

When you publish the application in the above procedures, the following properties are inserted into your project file by the Publish Wizard. These properties directly influence how the ClickOnce application is produced.

In CmdLineDemo.vbproj / CmdLineDemo.csproj:

<AssemblyOriginatorKeyFile>WindowsApplication3.snk</AssemblyOriginatorKeyFile>  
<GenerateManifests>true</GenerateManifests>  
<TargetZone>LocalIntranet</TargetZone>  
<PublisherName>Microsoft</PublisherName>  
<ProductName>CmdLineDemo</ProductName>  
<PublishUrl>https://localhost/CmdLineDemo</PublishUrl>  
<Install>true</Install>  
<ApplicationVersion>1.0.0.*</ApplicationVersion>  
<ApplicationRevision>1</ApplicationRevision>  
<UpdateEnabled>true</UpdateEnabled>  
<UpdateRequired>false</UpdateRequired>  
<UpdateMode>Foreground</UpdateMode>  
<UpdateInterval>7</UpdateInterval>  
<UpdateIntervalUnits>Days</UpdateIntervalUnits>  
<UpdateUrlEnabled>false</UpdateUrlEnabled>  
<IsWebBootstrapper>true</IsWebBootstrapper>  
<BootstrapperEnabled>true</BootstrapperEnabled>  

You can override any of these properties at the command line without altering the project file itself. For example, the following will build the ClickOnce application deployment without the bootstrapper:

msbuild /target:publish /property:BootstrapperEnabled=false  

Publishing properties are controlled in Visual Studio from the Publish, Security, and Signing property pages of the Project Designer. Below is a description of the publishing properties, along with an indication of how each is set in the various property pages of the application designer:

InstallURL, SupportUrl, PublishURL, and UpdateURL

The following table shows the four URL options for ClickOnce deployment.

URL option Description
PublishURL Required if you are publishing your ClickOnce application to a Web site.
InstallURL Optional. Set this URL option if the installation site is different than the PublishURL. For example, you could set the PublishURL to an FTP path and set the InstallURL to a Web URL.
SupportURL Optional. Set this URL option if the support site is different than the PublishURL. For example, you could set the SupportURL to your company's customer support Web site.
UpdateURL Optional. Set this URL option if the update location is different than the InstallURL. For example, you could set the PublishURL to an FTP path and set the UpdateURL to a Web URL.

See Also

GenerateBootstrapper
GenerateApplicationManifest
GenerateDeploymentManifest
ClickOnce Security and Deployment
Walkthrough: Manually Deploying a ClickOnce Application