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?
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)
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("""
© 2022 - 2024 — McMap. All rights reserved.