Skip to content

Commit bddd734

Browse files
althurmanjoshkempner
authored andcommitted
Fix package dependencies (#72)
* Fix dependencies when packing nuget - Use lower case dependency - Add logic to update package dependencies in nuspec file based on the framework version
1 parent d842330 commit bddd734

File tree

3 files changed

+187
-18
lines changed

3 files changed

+187
-18
lines changed

src/ReactiveDomain.UI.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
<dependencies>
1313
<group targetFramework=".NETFramework4.5.2">
1414
<dependency id="ReactiveDomain" version="0.8.21.1" exclude="Build,Analyzers" />
15-
<dependency id="ReactiveUI" version="7.4.0" exclude="Build,Analyzers" />
15+
<dependency id="reactiveui" version="7.4.0" exclude="Build,Analyzers" />
1616
</group>
1717
<group targetFramework=".NETFramework4.7.2">
1818
<dependency id="ReactiveDomain" version="0.8.21.1" exclude="Build,Analyzers" />
19-
<dependency id="ReactiveUI" version="8.7.2" exclude="Build,Analyzers" />
19+
<dependency id="reactiveui" version="8.7.2" exclude="Build,Analyzers" />
2020
</group>
2121
<group targetFramework=".NETStandard2.0">
2222
<dependency id="ReactiveDomain" version="0.8.21.1" exclude="Build,Analyzers" />
23-
<dependency id="ReactiveUI" version="8.7.2" exclude="Build,Analyzers" />
23+
<dependency id="reactiveui" version="8.7.2" exclude="Build,Analyzers" />
2424
</group>
2525
</dependencies>
2626
<references>

src/build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<Company>PerkinElmer,Linedata</Company>
2323
<Copyright>Copyright © 2014-2019 PerkinElmer Inc., Linedata Inc.</Copyright>
2424
<Description />
25-
<AssemblyVersion>0.8.21.6</AssemblyVersion>
26-
<FileVersion>0.8.21.6</FileVersion>
25+
<AssemblyVersion>0.8.21.7</AssemblyVersion>
26+
<FileVersion>0.8.21.7</FileVersion>
2727
<NeutralLanguage />
2828
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
2929
<DebugSymbols>true</DebugSymbols>

tools/CreateNuget.ps1

Lines changed: 182 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,23 @@ Write-Host ("Powershell script location is " + $PSScriptRoot)
3434

3535
$ReactiveDomainDll = $PSScriptRoot + "\..\bld\Release\net472\ReactiveDomain.Core.dll"
3636
$RDVersion = (Get-Item $ReactiveDomainDll).VersionInfo.FileVersion
37+
3738
$ReactiveDomainNuspec = $PSScriptRoot + "\..\src\ReactiveDomain.nuspec"
39+
$RDFoundationProject = $PSScriptRoot + "\..\src\ReactiveDomain.Foundation\ReactiveDomain.Foundation.csproj"
40+
$RDMessagingProject = $PSScriptRoot + "\..\src\ReactiveDomain.Messaging\ReactiveDomain.Messaging.csproj"
41+
$RDPersistenceProject = $PSScriptRoot + "\..\src\ReactiveDomain.Persistence\ReactiveDomain.Persistence.csproj"
42+
$RDPrivateLedgerProject = $PSScriptRoot + "\..\src\ReactiveDomain.PrivateLedger\ReactiveDomain.PrivateLedger.csproj"
43+
$RDTransportProject = $PSScriptRoot + "\..\src\ReactiveDomain.Transport\ReactiveDomain.Transport.csproj"
44+
3845
$ReactiveDomainTestingNuspec = $PSScriptRoot + "\..\src\ReactiveDomain.Testing.nuspec"
46+
$ReactiveDomainTestingProject = $PSScriptRoot + "\..\src\ReactiveDomain.Testing\ReactiveDomain.Testing.csproj"
47+
3948
$ReactiveDomainUINuspec = $PSScriptRoot + "\..\src\ReactiveDomain.UI.nuspec"
49+
$RDUIProject = $PSScriptRoot + "\..\src\ReactiveDomain.UI\ReactiveDomain.UI.csproj"
50+
4051
$ReactiveDomainUITestingNuspec = $PSScriptRoot + "\..\src\ReactiveDomain.UI.Testing.nuspec"
52+
$RDUITestingProject = $PSScriptRoot + "\..\src\ReactiveDomain.UI.Testing\ReactiveDomain.UI.Testing.csproj"
53+
4154
$nuget = $PSScriptRoot + "\..\src\.nuget\nuget.exe"
4255

4356
Write-Host ("Reactive Domain version is " + $RDVersion)
@@ -48,37 +61,193 @@ Write-Host ("ReactiveDomain.UI nuspec file is " + $ReactiveDomainUINuspec)
4861
Write-Host ("ReactiveDomain.UI.Testing nuspec file is " + $ReactiveDomainUITestingNuspec)
4962
Write-Host ("Branch is file is " + $branch)
5063

51-
function UpdateDependencyVersions([string]$Nuspec)
64+
class PackagRef
65+
{
66+
[string]$Version
67+
[string]$ComparisonOperator
68+
[string]$Framework
69+
}
70+
71+
# GetPackageRefFromProject
72+
#
73+
# Helper function to get a specific PackageRef from a .csproj file
74+
# Parses and returns a PackagRef object (defined above) that contains:
75+
# Version - (version of the package)
76+
# ConditionOperator - (the equality operator for a framework, == or !=)
77+
# Framework - The framework this Packageref applies to: (net452, net472, netstandard2.0)
78+
#
79+
function GetPackageRefFromProject([string]$Id, [string]$CsProj, [string]$Framework)
5280
{
81+
[xml]$xml = Get-Content -Path $CsProj -Encoding UTF8
82+
83+
$Xpath = "//Project/ItemGroup/PackageReference[@Include='" + $Id + "']"
84+
$targetPackage = $xml | Select-XML -XPath $Xpath
85+
$currentCondition = ""
86+
$compOperator = ""
87+
$currentFramework = ""
88+
$currentVersion = ""
89+
90+
# There may be duplicates of the same package when there are different versions
91+
# for different frameworks (i.e. ReactiveUI). Therefore if our search
92+
# returns more than one node, then we take the one that matches
93+
# the Framework in its Condition
94+
95+
if ($targetPackage.Node.Count -gt 1)
96+
{
97+
foreach ($tn in $targetPackage.Node)
98+
{
99+
if ($tn.Condition -match $Framework )
100+
{
101+
$currentCondition = $tn.Condition
102+
$currentVersion = $tn.Version
103+
}
104+
}
105+
}
106+
else
107+
{
108+
$currentCondition = $targetPackage.Node.Condition
109+
$currentVersion = $targetPackage.Node.Version
110+
}
111+
112+
if ($currentCondition -match "==")
113+
{
114+
$compOperator = "=="
115+
}
116+
117+
if ($currentCondition -match "!=")
118+
{
119+
$compOperator = "!="
120+
}
121+
122+
if ($currentCondition -match "net452")
123+
{
124+
$currentFramework = "net452"
125+
}
53126

127+
if ($currentCondition -match "net472")
128+
{
129+
$currentFramework = "net472"
130+
}
131+
132+
if ($currentCondition -match "netstandard2.0")
133+
{
134+
$currentFramework = "netstandard2.0"
135+
}
136+
137+
$myObj = New-Object -TypeName PackagRef
138+
$myObj.Version = $currentVersion
139+
$myObj.ComparisonOperator = $compOperator
140+
$myObj.Framework = $currentFramework
141+
142+
return $myObj
143+
}
144+
145+
# UpdateDependencyVersions
146+
#
147+
# Helper function that updates all non-ReactiveDomain dependencies
148+
# in a nuspec file. Loops through all dependencies listed in a
149+
# nuspec file and gets the versions from its
150+
# entry in the corresponding .csproj file
151+
#
152+
function UpdateDependencyVersions([string]$Nuspec, [string]$CsProj)
153+
{
54154
Write-Host "Updating dependency versions of: " $Nuspec
55155

56-
[xml]$xml = Get-Content -Path $Nuspec
156+
[xml]$xml = Get-Content -Path $Nuspec -Encoding UTF8
57157
$dependencyNodes = $xml.package.metadata.dependencies.group.dependency
58158

59-
foreach($node in $dependencyNodes)
159+
160+
$f452 = $xml | Select-XML -XPath "//package/metadata/dependencies/group[@targetFramework='.NETFramework4.5.2']"
161+
$framework452Nodes = $f452.Node.ChildNodes
162+
163+
$f472 = $xml | Select-XML -XPath "//package/metadata/dependencies/group[@targetFramework='.NETFramework4.7.2']"
164+
$framework472Nodes = $f472.Node.ChildNodes
165+
166+
$netstandard2 = $xml | Select-XML -XPath "//package/metadata/dependencies/group[@targetFramework='.NETStandard2.0']"
167+
$netstandard2Nodes = $netstandard2.Node.ChildNodes
168+
169+
foreach($refnode in $framework452Nodes)
60170
{
61-
if ($node.id.Contains("ReactiveDomain"))
171+
if ( $refnode.id -match "ReactiveDomain")
62172
{
63-
$node.version = $RDVersion
173+
$refnode.version = $RDVersion
174+
continue
64175
}
176+
177+
$pRef = GetPackageRefFromProject $refnode.id $CsProj "net452"
178+
if ((($pRef.ComparisonOperator -eq "" -or $pRef.Framework -eq "") -or
179+
($pRef.ComparisonOperator -eq "==" -and $pRef.Framework -eq "net452") -or
180+
($pRef.ComparisonOperator -eq "!=" -and $pRef.Framework -ne "net452")) -and
181+
($pRef.version -ne ""))
182+
{
183+
$refnode.version = $pRef.Version
184+
}
65185
}
66-
$xml.Save($Nuspec)
67186

68-
Write-Host "Updated dependency versions of: $Nuspec"
187+
foreach($refnode in $framework472Nodes)
188+
{
189+
if ( $refnode.id -match "ReactiveDomain")
190+
{
191+
$refnode.version = $RDVersion
192+
continue
193+
}
194+
195+
$pRef = GetPackageRefFromProject $refnode.id $CsProj "net472"
196+
if ((($pRef.ComparisonOperator -eq "" -or $pRef.Framework -eq "") -or
197+
($pRef.ComparisonOperator -eq "==" -and $pRef.Framework -eq "net472") -or
198+
($pRef.ComparisonOperator -eq "!=" -and $pRef.Framework -ne "net472")) -and
199+
($pRef.version -ne ""))
200+
{
201+
$refnode.version = $pRef.Version
202+
}
203+
}
204+
205+
foreach($refnode in $netstandard2Nodes)
206+
{
207+
if ( $refnode.id -match "ReactiveDomain")
208+
{
209+
$refnode.version = $RDVersion
210+
continue
211+
}
212+
213+
$pRef = GetPackageRefFromProject $refnode.id $CsProj "netstandard2.0"
214+
if ((($pRef.ComparisonOperator -eq "" -or $pRef.Framework -eq "") -or
215+
($pRef.ComparisonOperator -eq "==" -and $pRef.Framework -eq "netstandard2.0") -or
216+
($pRef.ComparisonOperator -eq "!=" -and $pRef.Framework -ne "netstandard2.0")) -and
217+
($pRef.version -ne ""))
218+
{
219+
$refnode.version = $pRef.Version
220+
}
221+
}
222+
223+
$xml.Save($Nuspec)
224+
Write-Host "Updated dependency versions of: $Nuspec"
69225
}
70226

227+
# Make the nuget.exe update itself (We must be at least at nuget 5.0 for this all to work) **************
71228
& $nuget update -self
72229

73-
# Update the corresponding ReactiveDomain dependency versions in the nuspec files ***********************************************
230+
# Update the dependency versions in the nuspec files ****************************************************
74231

75-
UpdateDependencyVersions($ReactiveDomainTestingNuspec)
76-
UpdateDependencyVersions($ReactiveDomainUINuspec)
77-
UpdateDependencyVersions($ReactiveDomainUITestingNuspec)
232+
# These all go into updating the main ReactiveDomain.nuspec
233+
UpdateDependencyVersions $ReactiveDomainNuspec $RDFoundationProject
234+
UpdateDependencyVersions $ReactiveDomainNuspec $RDMessagingProject
235+
UpdateDependencyVersions $ReactiveDomainNuspec $RDPersistenceProject
236+
UpdateDependencyVersions $ReactiveDomainNuspec $RDPrivateLedgerProject
237+
UpdateDependencyVersions $ReactiveDomainNuspec $RDTransportProject
78238

79-
# *******************************************************************************************************************************
239+
# These go into updating the ReactiveDomainUI.nuspec
240+
UpdateDependencyVersions $ReactiveDomainUINuspec $RDUIProject
241+
242+
# These go into updating the ReactiveDomainTesting.nuspec
243+
UpdateDependencyVersions $ReactiveDomainTestingNuspec $ReactiveDomainTestingProject
244+
245+
# These go into updating the ReactiveDomain.UI.Testing.nuspec
246+
UpdateDependencyVersions $ReactiveDomainUITestingNuspec $RDUITestingProject
247+
248+
# *******************************************************************************************************
80249

81-
# Pack the nuspec files to create the .nupkg files using the set versionString *************************************************
250+
# Pack the nuspec files to create the .nupkg files using the set versionString *************************
82251
$versionString = $RDVersion
83252
& $nuget pack $ReactiveDomainNuspec -Version $versionString
84253
& $nuget pack $ReactiveDomainTestingNuspec -Version $versionString

0 commit comments

Comments
 (0)