-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateClickOnce.ps1
More file actions
162 lines (127 loc) · 5.33 KB
/
CreateClickOnce.ps1
File metadata and controls
162 lines (127 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
[CmdletBinding()]
Param(
[Parameter(
Position=1,
HelpMessage='Base url for target deployment'
)]
[Alias('url')]
[ValidateNotNullOrEmpty()]
[string]$baseUrl,
[Parameter(
Position=2,
HelpMessage='Identifier for ClickOnce to determine if this is an upgrade of a previous version'
)]
[Alias('id')]
[ValidateNotNullOrEmpty()]
[string]$clickOnceApplicationIdentity,
[Parameter(
Position=3,
HelpMessage='Application title displayed to the user'
)]
[Alias('title')]
[ValidateNotNullOrEmpty()]
[string]$applicationTitle
)
$ErrorActionPreference = "Stop"
$executable = 'YourApp.exe'
$signingCert = 'YourCert.pfx'
$deploymentManifest = 'YourApp.application'
# Artifact locations. We are copying the App from \App to \Website\App and converting
# it to ClickOnce format.
$appFolder = '..\App'
$websiteFolder = '..\Website'
$websiteAppFolder = '..\Website\App'
$launcher = '..\Launcher\Launcher.exe'
# Processor can be x86, x64 or msil
$processor = 'msil'
# This only controls the icon displayed at install / upgrade time. There is a separate registry entry
# needed in the Uninstall key to make it display in Add/Remove Programs, and we don't do that yet.
$iconFile = 'YourIcon.ico'
$company = 'YourCo'
# Remove trailing slash.
$baseUrl = $baseUrl.TrimEnd('/')
# Copy Launcher.exe to the input folder.
Copy-Item $launcher $appFolder
# Copy the App directory contents into the Website\App folder, adding the .deploy extension to each file.
Copy-Item $appFolder $websiteFolder -Recurse -Force
# Add a ".deploy" extension to all files in the \Website\App folder
foreach ($item in (Get-ChildItem $websiteAppFolder -Recurse -Attributes !Directory))
{
Rename-Item $item -NewName "$($item.Name).deploy"
}
# Copy the iconFile in verbatim (no .deploy extension)
Copy-Item $appFolder\$iconFile $websiteAppFolder\$iconFile
# Read the version number from the main executable
$version = (Get-Item $appFolder\$executable).VersionInfo.FileVersion
# Compute name of YourApp.exe.manifest and upgrade URL
$appManifest = "$executable.manifest"
$upgradeUrl = "$baseUrl/app/$deploymentManifest"
## Install the MAGE tool from nuget
dotnet new tool-manifest --force
dotnet tool install microsoft.dotnet.mage --version 5.0.0
# Initially we used the standard dotnet mage Launcher.exe but this is not compatible
# with -Processor x86 - instead we created our own.
# dotnet mage `
# -AddLauncher $executable `
# -TargetDirectory $appFolder
# Create the application manifest
dotnet mage `
-New Application `
-ToFile $appManifest `
-Name $applicationTitle `
-Version $version `
-FromDirectory $appFolder `
-IconFile $iconFile `
-Processor $processor
# Sign the application manifest
dotnet mage `
-Sign $appManifest `
-CertFile $signingCert
# Create the deployment manifest (exename.application) file
dotnet mage `
-New Deployment `
-Install true `
-Name $clickOnceApplicationIdentity `
-Publisher $company `
-Version $version `
-AppManifest $appManifest `
-ToFile $deploymentManifest `
-ProviderURL $upgradeUrl `
-Processor $processor
# For some reason the MinVersion parameter only works on Update so update the .application file here
# (looks like this bug may be fixed in MAGE 5.0.3 onwards)
dotnet mage `
-Update $deploymentManifest `
-MinVersion $version `
-Publisher $company
# Certain properties are not generated by dotnet mage (or the older Mage.exe)
# but were generated by the old <GenerateDeploymentManifest> build task. Luckily
# they are just plain XML so we can add them in easily enough.
[xml]$xml = Get-Content $deploymentManifest
# Set up the namespaces
[System.Xml.XmlNamespaceManager] $nsm = New-Object System.Xml.XmlNamespaceManager $xml.NameTable
$asmv1 = 'urn:schemas-microsoft-com:asm.v1'
$asmv2 = 'urn:schemas-microsoft-com:asm.v2'
$cov1 = 'urn:schemas-microsoft-com:clickonce.v1'
$nsm.AddNamespace('asmv1', $asmv1)
$nsm.AddNamespace('asmv2', $asmv2)
$assemblyIdentity = $xml.SelectSingleNode('asmv1:assembly/asmv1:assemblyIdentity', $nsm)
$asmv1Description = $xml.SelectSingleNode('asmv1:assembly/asmv1:description', $nsm)
$asmv1Deployment = $xml.SelectSingleNode('asmv1:assembly/asmv2:deployment', $nsm)
# Update the XML attributes
$assemblyIdentity.SetAttribute('name', $clickOnceApplicationIdentity)
$asmv1Description.SetAttribute('publisher', $asmv2, $company)
$asmv1Description.SetAttribute('product', $asmv2, $applicationTitle)
# This tells ClickOnce that the files will all have the .deploy extension
$asmv1Deployment.SetAttribute('mapFileExtensions', 'true')
# Turns on the desktop shortcuts.
$asmv1Deployment.SetAttribute('createDesktopShortcut', $cov1, 'true')
# When saving XML, needs the absolute path
$xml.Save((Resolve-Path $deploymentManifest));
# Sign the deployment manifest
dotnet mage `
-Sign $deploymentManifest `
-CertFile $signingCert
# YourApp.exe.manifest and YourApp.application copied to the website folder now they have been signed.
Copy-Item $appManifest $websiteAppFolder
Copy-Item $deploymentManifest $websiteAppFolder