Skip to content

Commit 4f6249a

Browse files
authored
add version template (#3355)
Co-authored-by: freddydk <[email protected]>
1 parent 256d0e6 commit 4f6249a

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

NuGet/New-BcNuGetPackage.ps1

+45-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@
3131
Template to calculate the id of the dependencies
3232
The template can contain {id}, {name} and {publisher} which will be replaced with the values from the corresponding dependency from app.json
3333
The default is '{publisher}.{name}.{id}'
34+
.Parameter dependencyVersionTemplate
35+
Template to calculate the version field of the dependencies, default is {version}
36+
The template can contain {version} which will be replaced with the verson from the corresponding dependency from app.json
37+
The template can also contain {major},{minor},{build} and {revision} which will be replaced with the fields from the version
38+
The template can also contain {major+1},{minor+1},{build+1} and {revision+1} which will be replaced with the fields from the version incremented by 1
39+
.Parameter applicationDependencyId
40+
Id of the application dependency
41+
The default is 'Microsoft.Application'
42+
.Parameter applicationDependency
43+
Version/Template of the application dependency, default is the Application version from the app.json file
44+
The template can contain {version} which will be replaced with the verson from the corresponding dependency from app.json
45+
The template can also contain {major},{minor},{build} and {revision} which will be replaced with the fields from the version
46+
The template can also contain {major+1},{minor+1},{build+1} and {revision+1} which will be replaced with the fields from the version incremented by 1
47+
.Parameter platformDependencyId
48+
Id of the platform dependency
49+
The default is 'Microsoft.Platform'
50+
.Parameter platformDependency
51+
Version/Template of the platform dependency, default is the Platform version from the app.json file
52+
The template can contain {version} which will be replaced with the verson from the corresponding dependency from app.json
53+
The template can also contain {major},{minor},{build} and {revision} which will be replaced with the fields from the version
54+
The template can also contain {major+1},{minor+1},{build+1} and {revision+1} which will be replaced with the fields from the version incremented by 1
3455
.Parameter destinationFolder
3556
Folder to create the NuGet package in. Defeault it to create a temporary folder and delete it after the NuGet package has been created
3657
.Example
@@ -62,12 +83,16 @@ Function New-BcNuGetPackage {
6283
[Parameter(Mandatory=$false)]
6384
[string] $dependencyIdTemplate = '{publisher}.{name}.{id}',
6485
[Parameter(Mandatory=$false)]
86+
[string] $dependencyVersionTemplate = '{version}',
87+
[Parameter(Mandatory=$false)]
6588
[string] $applicationDependencyId = 'Microsoft.Application',
6689
[Parameter(Mandatory=$false)]
6790
[string] $applicationDependency = '',
6891
[Parameter(Mandatory=$false)]
6992
[string] $platformDependencyId = 'Microsoft.Platform',
7093
[Parameter(Mandatory=$false)]
94+
[string] $platformDependency = '',
95+
[Parameter(Mandatory=$false)]
7196
[string] $runtimeDependencyId = '{publisher}.{name}.runtime-{version}',
7297
[switch] $isIndirectPackage,
7398
[Parameter(Mandatory=$false)]
@@ -81,6 +106,10 @@ Function New-BcNuGetPackage {
81106
$stream.Write($bytes,0,$bytes.Length)
82107
}
83108

109+
function GetDependencyVersionStr([string] $template, [System.Version] $version) {
110+
return $template.Replace('{version}',"$version").Replace('{major}',$version.Major).Replace('{minor}',$version.Minor).Replace('{build}',$version.Build).Replace('{revision}',$version.Revision).Replace('{major+1}',($version.Major+1)).Replace('{minor+1}',($version.Minor+1)).Replace('{build+1}',($version.Build+1)).Replace('{revision+1}',($version.Revision+1))
111+
}
112+
84113
Write-Host "Create NuGet package"
85114
Write-Host "AppFile:"
86115
Write-Host $appFile
@@ -134,10 +163,21 @@ Function New-BcNuGetPackage {
134163
if (-not $packageAuthors) {
135164
$packageAuthors = $appJson.publisher
136165
}
137-
if (-not $applicationDependency) {
138-
if ($appJson.PSObject.Properties.Name -eq 'Application' -and $appJson.Application) {
166+
if ($appJson.PSObject.Properties.Name -eq 'Application' -and $appJson.Application) {
167+
if (-not $applicationDependency) {
139168
$applicationDependency = $appJson.Application
140169
}
170+
else {
171+
$applicationDependency = GetDependencyVersionStr -template $applicationDependency -version ([System.Version]::Parse($appJson.Application))
172+
}
173+
}
174+
if ($appJson.PSObject.Properties.Name -eq 'Platform' -and $appJson.Platform) {
175+
if (-not $platformDependency) {
176+
$platformDependency = $appJson.Platform
177+
}
178+
else {
179+
$platformDependency = GetDependencyVersionStr -template $platformDependency -version ([System.Version]::Parse($appJson.Platform))
180+
}
141181
}
142182

143183
if ($prereleaseTag) {
@@ -182,7 +222,7 @@ Function New-BcNuGetPackage {
182222
$id = Get-BcNuGetPackageId -packageIdTemplate $dependencyIdTemplate -publisher $_.publisher -name $_.name -id $dependencyId -version $_.version.replace('.','-')
183223
$XmlObjectWriter.WriteStartElement("dependency")
184224
$XmlObjectWriter.WriteAttributeString("id", $id)
185-
$XmlObjectWriter.WriteAttributeString("version", $_.version)
225+
$XmlObjectWriter.WriteAttributeString("version", (GetDependencyVersionStr -template $dependencyVersionTemplate -version ([System.Version]::Parse($_.version))))
186226
$XmlObjectWriter.WriteEndElement()
187227
}
188228
}
@@ -192,10 +232,10 @@ Function New-BcNuGetPackage {
192232
$XmlObjectWriter.WriteAttributeString("version", $applicationDependency)
193233
$XmlObjectWriter.WriteEndElement()
194234
}
195-
if ($appJson.PSObject.Properties.Name -eq 'Platform' -and $appJson.Platform) {
235+
if ($platformDependency) {
196236
$XmlObjectWriter.WriteStartElement("dependency")
197237
$XmlObjectWriter.WriteAttributeString("id", $platformDependencyId)
198-
$XmlObjectWriter.WriteAttributeString("version", $appJson.Platform)
238+
$XmlObjectWriter.WriteAttributeString("version", $platformDependency)
199239
$XmlObjectWriter.WriteEndElement()
200240
}
201241
if ($isIndirectPackage.IsPresent) {

ReleaseNotes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
6.0.7
22
Issue 3347 Download-BcNuGetPackageToFolder to support package description for app name if title is not specified
3+
Support dependency version templates on NuGet packages
34

45
6.0.6
56
Include Microsoft_Business Foundation Test Libraries.app when importing test libraries (and tests)

0 commit comments

Comments
 (0)