Change appx package version from vNext build
Asked Answered
E

2

5

I've created a UWP project that I'm building with a TFS vNext build. When it creates the package, it uses the version from the appx manifest. Instead, I'd like to set the version number from the msbuild command line. Is this possible?

Eremite answered 7/5, 2017 at 2:37 Comment(2)
Thx,I am going to ask this question.I want to change the appx package version in any way.Myoglobin
i am using a powershell script that updates the version number in the manifest file before buildingSwoop
E
9

I ended up doing the same thing @Dave Smits:

(1) Copied the contents of Package.appxmanifest to a new file called Package.appxmanifest.template, and added it to the project.

(2) Kept the Package.appxmanifest file in the solution, but excluded it from source control.

(3) Created a powershell script and added it to source control (see below).

(4) Execute this powershell script at build time. For me, this meant adding a PowerShell step prior to building the solution.

param([io.fileinfo]$template, [io.fileinfo]$package, [string]$version)
[xml]$xml = gc $template
$xml.Package.Identity.Version = $version; 
$xml.Save($package)
Eremite answered 10/5, 2017 at 18:44 Comment(0)
T
0

Assuming you're dealing with C#, for the sake of continuity across binaries, you'll likely want to update your Properties\AssemblyInfo.cs files too. As it stands, the accepted answer accomplishes this task quicker for strictly the manifest file. However you can use this script to work on non-XML files.

It also has two pre-pended string parameters to reduce regex formatting headaches.

VersionUpdater.ps1

param([string]$filePath,[string]$versionString,[string]$prePendedStringRegex,[string]$prePendedString)
function UpdateVersionString() {
    $contents=[System.IO.File]::ReadAllText($filePath)
    $contents=[RegEx]::Replace($contents, "$prePendedStringRegex\d+\.\d+\.\d+\.\d+", ("$prePendedString" + $versionString))
    [System.IO.File]::WriteAllText($filePath, $contents)
}
UpdateVersionString

use:

VersionUpdater.ps1 -filePath "C:\path\to\Project\Package.appxmanifest" -versionString "1.2.3.4" -prePendedStringRegex " Version=""" -prePendedString " Version="""

VersionUpdater.ps1 -filePath "C:\path\to\Project\Properties\AssemblyInfo.cs" -versionString "1.2.3.4" -prePendedStringRegex " AssemblyVersion\(""" -prePendedString " AssemblyVersion("""

VersionUpdater.ps1 -filePath "C:\path\to\Project\Properties\AssemblyInfo.cs" -versionString "1.2.3.4" -prePendedStringRegex " AssemblyFileVersion\(""" -prePendedString " AssemblyFileVersion("""
Tressatressia answered 17/8, 2023 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.