Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 48 additions & 19 deletions Source/Activities/ClickOnce/ClickOnceDeployment.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
//-----------------------------------------------------------------------
// <copyright file="ClickOnceDeployment.cs">(c) http://TfsBuildExtensions.codeplex.com/. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved.</copyright>
//-----------------------------------------------------------------------

using System;
using System.Activities;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using Microsoft.TeamFoundation.Build.Client;

namespace TfsBuildExtensions.Activities.ClickOnce
{
using System;
using System.Activities;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using Microsoft.TeamFoundation.Build.Client;

/// <summary>
/// ClickOnceDeployment
/// </summary>
Expand All @@ -21,6 +22,26 @@ public sealed class ClickOnceDeployment : BaseCodeActivity
{
private InArgument<string> processor = "x86";

/// <summary>
/// Publisher
/// </summary>
public InArgument<string> Publisher { get; set; }

/// <summary>
/// Create a desktop shortcut for the Application
/// </summary>
public InArgument<bool> CreateDesktopShortcut { get; set; }

/// <summary>
/// Name of Icon File
/// </summary>
public InArgument<string> IconFile { get; set; }

/// <summary>
/// Timestamp Server Location
/// </summary>
public InArgument<string> TimestampUri { get; set; }

/// <summary>
/// Sets the Processor to use. Default is x86.
/// </summary>
Expand Down Expand Up @@ -103,6 +124,10 @@ protected override void InternalExecute()
string installLocation = this.InstallLocation.Get(this.ActivityContext);
string targetFrameworkVersion = this.TargetFrameworkVersion.Get(this.ActivityContext);
string manifestCertificateThumbprint = this.ManifestCertificateThumbprint.Get(this.ActivityContext);
string timestampUri = this.TimestampUri.Get(this.ActivityContext);
bool createDesktopShortcut = this.CreateDesktopShortcut.Get(this.ActivityContext);
string publisher = this.Publisher.Get(this.ActivityContext);
string iconFile = this.IconFile.Get(this.ActivityContext);

try
{
Expand All @@ -122,26 +147,29 @@ protected override void InternalExecute()
string manifestCertificateThumbprintArg = !string.IsNullOrEmpty(manifestCertificateThumbprint) ? "-CertHash " + manifestCertificateThumbprint : string.Empty;
string certFilePathArg = !string.IsNullOrEmpty(certFilePath) ? "-CertFile " + certFilePath : string.Empty;
string certPasswordArg = !string.IsNullOrEmpty(certPassword) ? "-Password " + certPassword : string.Empty;
string timestampUriArg = !string.IsNullOrEmpty(timestampUri) ? "-TimestampUri " + timestampUri : string.Empty;
string iconFileArg = !string.IsNullOrEmpty(iconFile) ? " -IconFile " + iconFile : string.Empty;

// Create Application Manifest
string args = "-New Application -Processor " + this.Processor.Get(this.ActivityContext) + " -ToFile \"" + toFile + "\\" + applicationName + ".exe.manifest\" -name " + applicationName + " -Version " + version + " -FromDirectory \"" + toFile + "\"";
string args = "-New Application -Processor " + this.Processor.Get(this.ActivityContext) + " -ToFile \"" + toFile + "\\" + applicationName + ".exe.manifest\" -name " + applicationName + " -Version " + version + " -FromDirectory \"" + toFile + "\"" + iconFileArg;
RunMage(mageFilePath, args);

// Sign Application Manifest
args = "-Sign \"" + toFile + "\\" + applicationName + ".exe.manifest\" " + manifestCertificateThumbprintArg + " " + certFilePathArg + " " + certPasswordArg;
RunMage(mageFilePath, args);
//args = "-Sign \"" + toFile + "\\" + applicationName + ".exe.manifest\" " + manifestCertificateThumbprintArg + " " + certFilePathArg + " " + certPasswordArg;
//RunMage(mageFilePath, args);

// rename all files to have a .deploy
RenameFiles(toFile);

// Sign Application Manifest
args = "-Sign \"" + toFile + "\\" + applicationName + ".exe.manifest\" " + manifestCertificateThumbprintArg + " " + certFilePathArg + " " + certPasswordArg;
args = "-Sign \"" + toFile + "\\" + applicationName + ".exe.manifest\" " + manifestCertificateThumbprintArg + " " + certFilePathArg + " " + certPasswordArg + " " + timestampUriArg;

RunMage(mageFilePath, args);

CreateDeploymentManifest(version, applicationName, publishLocation, targetFrameworkVersion);
CreateDeploymentManifest(version, applicationName, publishLocation, installLocation, targetFrameworkVersion, createDesktopShortcut, publisher);

// Sign Deployment Manifest
args = "-Sign \"" + publishLocation + "\\" + applicationName + ".application\" " + manifestCertificateThumbprintArg + " " + certFilePathArg + " " + certPasswordArg;
args = "-Sign \"" + publishLocation + "\\" + applicationName + ".application\" " + manifestCertificateThumbprintArg + " " + certFilePathArg + " " + certPasswordArg + " " + timestampUriArg;
RunMage(mageFilePath, args);

// Copy Deploy Manifest to parent folder
Expand Down Expand Up @@ -213,7 +241,7 @@ private static void RunMage(string mageFilePath, string args)
}
}

private static void CreateDeploymentManifest(string version, string applicationName, string publishLocation, string targetFrameworkVersion)
private static void CreateDeploymentManifest(string version, string applicationName, string publishLocation, string installLocation, string targetFrameworkVersion, bool createDesktopShortcut, string publisher)
{
Dictionary<string, string> metadata = new Dictionary<string, string>();
metadata.Add("TargetPath", "Application Files\\" + applicationName + "_" + version + "\\" + applicationName + ".exe.manifest");
Expand All @@ -223,15 +251,16 @@ private static void CreateDeploymentManifest(string version, string applicationN
AssemblyName = applicationName + ".application",
AssemblyVersion = version,
Product = applicationName,
Publisher = publisher,

// DeploymentUrl = installLocation,
DeploymentUrl = installLocation + applicationName + ".application",
Install = true,
UpdateEnabled = true,
UpdateMode = "Foreground",
OutputManifest = new TaskItem(publishLocation + "\\" + applicationName + ".application"),
MapFileExtensions = true,
EntryPoint = new TaskItem(publishLocation + @"\Application Files\" + applicationName + "_" + version + "\\" + applicationName + ".exe.manifest", metadata),
CreateDesktopShortcut = false,
CreateDesktopShortcut = createDesktopShortcut,
TargetFrameworkVersion = targetFrameworkVersion,
TargetFrameworkMoniker = ".NETFramework,Version=v" + targetFrameworkVersion,
MinimumRequiredVersion = version
Expand Down