Skip to content

Commit b0c3b15

Browse files
author
Brett Groff
committed
Reverse install and publish url values
- Noticed that I had the values for install and publish url's reversed so I fixed it. Publish url format is like a fileshare (\\fileshare\folder) and install url format is like a web url (http://fileshare/folder) - Updated the tests to reflect the reversal of values - Updated csproj file to reflect the reversal of values - Updated readme with parameter names and example. Note I had the example in the script file correct but it was wrong every where else!
1 parent ebd29f5 commit b0c3b15

4 files changed

Lines changed: 59 additions & 49 deletions

File tree

ReadMe.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ Setting the MinimumRequiredVersion property forces the ClickOnce application to
88

99
# Script Parameters
1010
* **ProjectFilePath** (required) - Path of the .csproj and .vbproj file to process.
11-
11+
1212
* **Version** - The Version to update the ClickOnce version number to. This version must be of the format Major.Minor.Build or Major.Minor.Build.Revision. The Build and Revision parts will be overridden by the BuildSystemsBuildId parameter, if it is provided. The Revision parts will be overriden by the IncrementProjectFilesRevision parameter, if it is provided.
1313

1414
* **BuildSystemsBuildId** - The build system's unique and auto-incrementing Build ID. This will be used to generate the Build and Revision parts of the new Version number. This will override the Build and Revision specified in the Version parameter, if it was provided. This parameter cannot be used with the IncrementProjectFilesRevision parameter.
15-
15+
1616
* **IncrementProjectFilesRevision** - If this switch is provided, the Revision from the project file will be incremented and used in the new ClickOnce Version. This will override the Revision specified in the Version parameter, if it was provided. This parameter cannot be used with the BuildSystemsBuildId parameter.
17-
17+
1818
* **UpdateMinimumRequiredVersionToCurrentVersion** - If this switch is provided, the ClickOnce MinimumRequiredVersion will be updated to match the new Version. Setting the MinimumRequiredVersion property forces the ClickOnce application to update automatically without prompting the user.
1919

20+
* **PublishUrl** - If this switch is provided, the ClickOnce PublishUrl will be updated. The publish url format is \\fileshare\foldername
21+
22+
* **InstallUrl** - If this switch is provided, the ClickOnce InstallUrl will be updated. The install url format is http://fileshare/foldername
2023

2124
# Examples
2225
Update a project file's ClickOnce version to the specified version.
@@ -52,4 +55,11 @@ Update a project file's ClickOnce version, ignoring the Revision part and increm
5255
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -Version '1.2.3' -IncrementProjectFilesRevision -UpdateMinimumRequiredVersionToCurrentVersion
5356
```
5457

55-
[AutoUpdateProjectsMinimumRequiredClickOnceVersionNugetPackageWebpage]: https://www.nuget.org/packages/AutoUpdateProjectsMinimumRequiredClickOnceVersion
58+
---
59+
60+
Update a project file's ClickOnce version and its install and publish url values.
61+
```
62+
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -Version 1.0.1.9 -PublishUrl "\\fileshare\foldername" -InstallUrl "http://fileshare/foldername"
63+
```
64+
65+
[AutoUpdateProjectsMinimumRequiredClickOnceVersionNugetPackageWebpage]: https://www.nuget.org/packages/AutoUpdateProjectsMinimumRequiredClickOnceVersion

Set-ProjectFilesClickOnceVersion.ps1

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<#
33
.SYNOPSIS
44
This script updates the ClickOnce version in a project file (.csproj or .vbproj), and may update the MinimumRequiredVersion to be this same version.
5-
5+
66
.DESCRIPTION
77
This script updates the current ClickOnce version in a project file (.csproj or .vbproj), and may update the MinimumRequiredVersion to be this same version.
88
Setting the MinimumRequiredVersion property forces the ClickOnce application to update automatically without prompting the user.
9-
9+
1010
.PARAMETER ProjectFilePath
1111
(required) Path of the .csproj and .vbproj file to process.
12-
12+
1313
.PARAMETER Version
1414
The Version to update the ClickOnce version number to. This version must be of the format Major.Minor.Build or Major.Minor.Build.Revision.
1515
The Build and Revision parts will be overridden by the BuildSystemsBuildId parameter, if it is provided.
@@ -19,12 +19,12 @@
1919
The build system's unique and auto-incrementing Build ID. This will be used to generate the Build and Revision parts of the new Version number.
2020
This will override the Build and Revision specified in the Version parameter, if it was provided.
2121
This parameter cannot be used with the IncrementProjectFilesRevision parameter.
22-
22+
2323
.PARAMETER IncrementProjectFilesRevision
2424
If this switch is provided, the Revision from the project file will be incremented and used in the new ClickOnce Version.
2525
This will override the Revision specified in the Version parameter, if it was provided.
2626
This parameter cannot be used with the BuildSystemsBuildId parameter.
27-
27+
2828
.PARAMETER UpdateMinimumRequiredVersionToCurrentVersion
2929
If this switch is provided, the ClickOnce MinimumRequiredVersion will be updated to match the new Version.
3030
Setting the MinimumRequiredVersion property forces the ClickOnce application to update automatically without prompting the user.
@@ -37,29 +37,29 @@
3737
3838
.EXAMPLE
3939
Update a project file's ClickOnce version to the specified version.
40-
40+
4141
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -Version '1.2.3.4'
4242
4343
.EXAMPLE
4444
Update the Build and Revision parts of a project file's ClickOnce version, based on a unique, auto-incrementing integer, such as a build system's Build ID.
45-
45+
4646
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -BuildSystemsBuildId 123456
4747
4848
.EXAMPLE
4949
Increment the Revision of a project file's ClickOnce version.
50-
50+
5151
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -IncrementProjectFilesRevision
5252
5353
.EXAMPLE
5454
Update a project file's ClickOnce Minimum Required Version to match its current version.
55-
55+
5656
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -UpdateMinimumRequiredVersionToCurrentVersion
57-
57+
5858
.EXAMPLE
5959
Update a project file's ClickOnce version, ignoring the Revision part and incrementing the Revision stored in the file, and update the Minimum Required Version to be this new version.
60-
60+
6161
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -Version '1.2.3' -IncrementProjectFilesRevision -UpdateMinimumRequiredVersionToCurrentVersion
62-
62+
6363
.EXAMPLE
6464
Update a project file's ClickOnce version using both Version and a unique, auto-incrementing integer, such as a build system's Build ID. This will keep the major and minor versions you specify but update the build and revision (e.g. 1.0.1.5745)
6565
@@ -68,12 +68,12 @@
6868
.EXAMPLE
6969
Update a project file's ClickOnce version and its install and publish url values.
7070
71-
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -Version 1.0.1.9 -PublishUrl "\\servername\foldername" -InstallUrl "http://servername/foldername"
71+
& .\Set-ProjectFilesClickOnceVersion.ps1 -ProjectFilePath "C:\SomeProject.csproj" -Version 1.0.1.9 -PublishUrl "\\fileshare\foldername" -InstallUrl "http://fileshare/foldername"
7272
7373
7474
.LINK
7575
Project Home: https://github.com/deadlydog/Set-ProjectFilesClickOnceVersion
76-
76+
7777
.NOTES
7878
Author: Daniel Schroeder
7979
Version: 2.0.0
@@ -125,7 +125,7 @@ function Get-XmlNamespaceManager([xml]$XmlDocument, [string]$NamespaceURI = "")
125125
{
126126
# If a Namespace URI was not given, use the Xml document's default namespace.
127127
if ([string]::IsNullOrEmpty($NamespaceURI)) { $NamespaceURI = $XmlDocument.DocumentElement.NamespaceURI }
128-
128+
129129
# In order for SelectSingleNode() to actually work, we need to use the fully qualified node path along with an Xml Namespace Manager, so set them up.
130130
[System.Xml.XmlNamespaceManager]$xmlNsManager = New-Object System.Xml.XmlNamespaceManager($XmlDocument.NameTable)
131131
$xmlNsManager.AddNamespace("ns", $NamespaceURI)
@@ -141,7 +141,7 @@ function Get-XmlNode([xml]$XmlDocument, [string]$NodePath, [string]$NamespaceURI
141141
{
142142
$xmlNsManager = Get-XmlNamespaceManager -XmlDocument $XmlDocument -NamespaceURI $NamespaceURI
143143
[string]$fullyQualifiedNodePath = Get-FullyQualifiedXmlNodePath -NodePath $NodePath -NodeSeparatorCharacter $NodeSeparatorCharacter
144-
144+
145145
# Try and get the node, then return it. Returns $null if the node was not found.
146146
$node = $XmlDocument.SelectSingleNode($fullyQualifiedNodePath, $xmlNsManager)
147147
return $node
@@ -159,36 +159,36 @@ function Get-XmlNodes([xml]$XmlDocument, [string]$NodePath, [string]$NamespaceUR
159159

160160
function Get-XmlElementsTextValue([xml]$XmlDocument, [string]$ElementPath, [string]$NamespaceURI = "", [string]$NodeSeparatorCharacter = '.')
161161
{
162-
# Try and get the node.
162+
# Try and get the node.
163163
$node = Get-XmlNode -XmlDocument $XmlDocument -NodePath $ElementPath -NamespaceURI $NamespaceURI -NodeSeparatorCharacter $NodeSeparatorCharacter
164-
164+
165165
# If the node already exists, return its value, otherwise return null.
166166
if ($node) { return $node.InnerText } else { return $null }
167167
}
168168

169169
function Set-XmlElementsTextValue([xml]$XmlDocument, [string]$ElementPath, [string]$TextValue, [string]$NamespaceURI = "", [string]$NodeSeparatorCharacter = '.')
170170
{
171-
# Try and get the node.
171+
# Try and get the node.
172172
$node = Get-XmlNode -XmlDocument $XmlDocument -NodePath $ElementPath -NamespaceURI $NamespaceURI -NodeSeparatorCharacter $NodeSeparatorCharacter
173-
173+
174174
# If the node already exists, update its value.
175175
if ($node)
176-
{
176+
{
177177
$node.InnerText = $TextValue
178178
}
179179
# Else the node doesn't exist yet, so create it with the given value.
180180
else
181181
{
182182
# Create the new element with the given value.
183183
$elementName = $ElementPath.Substring($ElementPath.LastIndexOf($NodeSeparatorCharacter) + 1)
184-
$element = $XmlDocument.CreateElement($elementName, $XmlDocument.DocumentElement.NamespaceURI)
184+
$element = $XmlDocument.CreateElement($elementName, $XmlDocument.DocumentElement.NamespaceURI)
185185
$textNode = $XmlDocument.CreateTextNode($TextValue)
186186
$element.AppendChild($textNode) > $null
187-
187+
188188
# Try and get the parent node.
189189
$parentNodePath = $ElementPath.Substring(0, $ElementPath.LastIndexOf($NodeSeparatorCharacter))
190190
$parentNode = Get-XmlNode -XmlDocument $XmlDocument -NodePath $parentNodePath -NamespaceURI $NamespaceURI -NodeSeparatorCharacter $NodeSeparatorCharacter
191-
191+
192192
if ($parentNode)
193193
{
194194
$parentNode.AppendChild($element) > $null
@@ -204,7 +204,7 @@ function Set-XmlNodesElementTextValue([xml]$xml, $node, $elementName, $textValue
204204
{
205205
if ($null -eq $node.($elementName))
206206
{
207-
$element = $xml.CreateElement($elementName, $xml.DocumentElement.NamespaceURI)
207+
$element = $xml.CreateElement($elementName, $xml.DocumentElement.NamespaceURI)
208208
$textNode = $xml.CreateTextNode($textValue)
209209
$element.AppendChild($textNode) > $null
210210
$node.AppendChild($element) > $null
@@ -224,7 +224,7 @@ $versionNumberRegex = New-Object System.Text.RegularExpressions.Regex "(?<MajorM
224224
# Open the Xml file and get the <PropertyGroup> elements with the ClickOnce properties in it.
225225
[xml]$xml = Get-Content -Path $ProjectFilePath
226226
$propertyGroups = Get-XmlNodes -XmlDocument $xml -NodePath 'Project.PropertyGroup'
227-
[Array]$clickOncePropertyGroups = $propertyGroups | Where-Object {
227+
[Array]$clickOncePropertyGroups = $propertyGroups | Where-Object {
228228
try
229229
{
230230
return ($_.ApplicationVersion -ne $null)
@@ -270,7 +270,7 @@ foreach ($clickOncePropertyGroup in $clickOncePropertyGroups)
270270
{
271271
$appVersion = $clickOncePropertyGroup.ApplicationVersion
272272
}
273-
273+
274274
# Get the Major, Minor, and Build parts of the version number.
275275
$majorMinorBuildMatch = $versionNumberRegex.Match($appVersion)
276276
if (!$majorMinorBuildMatch.Success)
@@ -280,20 +280,20 @@ foreach ($clickOncePropertyGroup in $clickOncePropertyGroups)
280280
$majorMinor = $majorMinorBuildMatch.Groups["MajorMinor"].Value
281281
[int]$build = $majorMinorBuildMatch.Groups["Build"].Value
282282
[int]$revision = -1
283-
283+
284284
# If a Revision was specified in the Version, get it.
285285
if (![string]::IsNullOrWhiteSpace($majorMinorBuildMatch.Groups["Revision"]))
286286
{
287287
$revision = [int]::Parse($majorMinorBuildMatch.Groups["Revision"])
288288
}
289-
289+
290290
# If we should be using the BuildSystemsBuildId for the Build and Revision.
291291
if ($BuildSystemsBuildId -gt -1)
292292
{
293293
# Use a calculation for the Build and Revision to prevent the Revision value from being too large, and to increment the Build value as the BuildSystemsBuildId continues to grow larger.
294294
$build = [int][Math]::Floor($BuildSystemsBuildId / $maxVersionPartValueAllowed)
295295
$revision = $BuildSystemsBuildId % $maxVersionPartValueAllowed
296-
296+
297297
Write-Verbose "Translated BuildSystemsBuildId '$BuildSystemsBuildId' into Build.Revision '$build.$revision'."
298298
}
299299

@@ -305,19 +305,19 @@ foreach ($clickOncePropertyGroup in $clickOncePropertyGroups)
305305
if ($null -eq $applicationRevisionString)
306306
{
307307
throw "Could not find the <ApplicationRevision> element in the project file '$ProjectFilePath'."
308-
}
308+
}
309309
if (!($applicationRevisionString -imatch '^\d+$'))
310310
{
311311
throw "The <ApplicationRevision> elements value '$applicationRevisionString' in the file '$ProjectFilePath' does not appear to be a valid integer."
312312
}
313-
313+
314314
$revision = [int]::Parse($applicationRevisionString)
315-
315+
316316
# If the Revision should be incremented, do it.
317317
if ($IncrementProjectFilesRevision)
318318
{
319319
$revision = $revision + 1
320-
320+
321321
# Make sure the Revision version part is not greater than the max allowed value.
322322
if ($revision -gt $maxVersionPartValueAllowed)
323323
{
@@ -326,12 +326,12 @@ foreach ($clickOncePropertyGroup in $clickOncePropertyGroups)
326326
}
327327
}
328328
}
329-
329+
330330
# Create the version number to use for the ClickOnce version.
331331
$newMajorMinorBuild = "$majorMinor.$build"
332332
$newVersionNumber = "$newMajorMinorBuild.$revision"
333333
Write-Output "Updating version number to be '$newVersionNumber'."
334-
334+
335335
# Write the new values to the file.
336336
Set-XmlNodesElementTextValue -xml $xml -node $clickOncePropertyGroup -elementName 'ApplicationVersion' -textValue "$newMajorMinorBuild.%2a"
337337
Set-XmlNodesElementTextValue -xml $xml -node $clickOncePropertyGroup -elementName 'ApplicationRevision' -textValue $revision.ToString()

Tests/RunTests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ function RunScriptWithParameters($parameters)
3333
return $matches["Version"]
3434
}
3535
# If $output contains multiple lines, it will be treated as a collection instead of a string and $matches will not be defined, so catch that case.
36-
catch { return $output }
36+
catch { return $output }
3737
}
3838
return $output
3939
}
40-
40+
4141
$testNumber = 0
4242
# Some tests are dependent on the order in which they are ran, which isn't ideal, but good enough for now.
4343

@@ -66,11 +66,11 @@ $output = RunScriptWithParameters "-Version '1.1.0.0' -BuildSystemsBuildId 12345
6666
if ($output -eq '1.1.1.57921') { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
6767

6868
Write-Host ("{0}. Use version and publish url parameter...." -f ++$testNumber)
69-
$output = RunScriptWithParameters "-Version '1.0.5.9' -PublishUrl 'http://testserver/folder'"
69+
$output = RunScriptWithParameters "-Version '1.0.5.9' -PublishUrl '\\fileshare\foldername'"
7070
# Multiple output statements are objects in an array in the order they are outputted
71-
if ($output[0].Contains('http://testserver/folder') -AND $output[1].Contains('1.0.5.9')) { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
71+
if ($output[0].Contains('\\fileshare\foldername') -AND $output[1].Contains('1.0.5.9')) { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
7272

7373
Write-Host ("{0}. Use BuildId parameter, publish url parameter and install url parameter...." -f ++$testNumber)
74-
$output = RunScriptWithParameters "-BuildSystemsBuildId 123456 -PublishUrl 'http://testserver/folder' -InstallUrl '\\fileshare\folder'"
74+
$output = RunScriptWithParameters "-BuildSystemsBuildId 123456 -PublishUrl '\\fileshare\foldername' -InstallUrl 'http://fileshare/foldername'"
7575
# Multiple output statements are objects in an array in the order they are outputted
76-
if ($output[0].Contains('http://testserver/folder') -AND $output[1].Contains('\\fileshare\folder') -AND $output[2].Contains('1.0.1.57921')) { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }
76+
if ($output[0].Contains('\\fileshare\foldername') -AND $output[1].Contains('http://fileshare/foldername') -AND $output[2].Contains('1.0.1.57921')) { Write-Host "Passed" } else { throw "Test $testNumber failed. Output was '$output'." }

Tests/TestFiles/TestProject.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1515
<WarningLevel>4</WarningLevel>
1616
<IsWebBootstrapper>false</IsWebBootstrapper>
17-
<PublishUrl>publish\</PublishUrl>
17+
<PublishUrl>\\fileshare\foldername</PublishUrl>
1818
<Install>true</Install>
1919
<InstallFrom>Disk</InstallFrom>
2020
<UpdateEnabled>true</UpdateEnabled>
@@ -24,7 +24,7 @@
2424
<UpdatePeriodically>false</UpdatePeriodically>
2525
<UpdateRequired>true</UpdateRequired>
2626
<MapFileExtensions>true</MapFileExtensions>
27-
<InstallUrl>\\publish\app</InstallUrl>
27+
<InstallUrl>http://fileshare/foldername</InstallUrl>
2828
<MinimumRequiredVersion>1.0.0.1</MinimumRequiredVersion>
2929
<ApplicationRevision>1</ApplicationRevision>
3030
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
@@ -128,7 +128,7 @@
128128
</BootstrapperPackage>
129129
</ItemGroup>
130130
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
131-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
131+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
132132
Other similar extension points exist, see Microsoft.Common.targets.
133133
<Target Name="BeforeBuild">
134134
</Target>

0 commit comments

Comments
 (0)