CoderSivu
CoderSivu

Reputation: 141

Generate setup.exe for ClickOnce deployment from command line using MSBuild

I have a MSBuild script that builds my windows forms application, generates the application manifest and signs it, then generates the deployment manifest. The script also generates the publish.htm file for me.

Now I need to generate the setup.exe file and so far I have not been able to figure out how VS generates it. How can I generate the setup.exe file using a MSBuild script?

Thank you in advance for your help!

Upvotes: 5

Views: 5647

Answers (2)

Doug
Doug

Reputation: 35136

The flags you want to msbuild are:

/target:publish

and:

/p:PublishDir=C:\Foo\

Notice that you must have a trailing \ on the publish dir or it simple perform the the dependent steps on publish (ie. build) and never actually generate an installer.

You may be interested in the msbuild npm package:

var msbuild = require('msbuild');
var path = require('path');

// Config
var source = 'source/Bar/Bar.App/Bar.App.csproj';
var deploy = path.join(__dirname, 'deploy');

// Build the project
var builder = new msbuild();
builder.sourcePath = source;
builder.overrideParams.push('/p:PublishDir=' + deploy + "\\"); // <-- Installer
builder.overrideParams.push('/Target:rebuild;publish');
builder.overrideParams.push('/P:Configuration=Release');
builder.overrideParams.push('/P:verbosity=diag');
builder.overrideParams.push('/P:Platform=x86');
builder.overrideParams.push('/fl');
builder.overrideParams.push('/flp:logfile=build.log;verbosity=diagnostic');
builder.publish();

...which you would run something like:

npm install msbuild
node builder.js

No powershell required.

Upvotes: 2

David Moore
David Moore

Reputation: 2526

You can use the built-in GenerateBootstrapper MSBuild task

When you do a Publish from Visual Studio, this is also what ClickOnce uses.

Check out C:\Windows\Microsoft.NET\Framework\\Microsoft.Common.Targets to see exactly what happens.

Look at the _DeploymentGenerateBootstrapper target.

Your CSharp project file contains some items and properties that this target uses to figure out:

  1. If it's going to generate a bootstrapper (BootstrapperEnabled property)
  2. The packages to generate the bootstrapper for (BootstrapperPackage item group)
  3. Where the packages will be installed from (BootstrapperComponentsLocation property)

Hopefully this makes sense. With a bit of work you can implement with your MSBuild file exactly what happens when you Publish from Visual Studio.

Upvotes: 3

Related Questions