diff --git a/UpdateNugetPackages.ps1 b/UpdateNugetPackages.ps1 index 60602f504e..6b9f620c72 100644 --- a/UpdateNugetPackages.ps1 +++ b/UpdateNugetPackages.ps1 @@ -1,19 +1,85 @@ #requires -Version 5 +[CmdletBinding()] +param( + [Parameter(Position = 1)] + [string] $CefVersion = "100.0.12", + [Parameter(Position = 2)] + [string] $CefSharpVersion = "", + [Parameter(Position = 3)] + [string] $BuildArches = "x86 x64 arm64" + ) # Update projects files # I haven't found a clean solution that allows for using just nuget.exe and dotnet.exe to do this # Update the vcxproj files first # Update the .Net csproj files modifying the xml file directly +$ARCHES = [System.Collections.ArrayList]$BuildArches.ToLower().Split(" "); +Set-StrictMode -version latest; +$ErrorActionPreference = "Stop"; + +if ($CefSharpVersion -eq "") +{ + $CefSharpVersion = $CefVersion + "0" +} + +function UpdateNupsecCommonArches() +{ + $nuspecFile = (Resolve-Path 'NuGet\CefSharp.Common.nuspec'); + $CefSharpNugetXml = [xml](Get-Content $nuspecFile ); + $ns = new-object Xml.XmlNamespaceManager $CefSharpNugetXml.NameTable + $ns.AddNamespace("ns", $CefSharpNugetXml.DocumentElement.NamespaceURI) + + $srcNode = $CefSharpNugetXml.SelectSingleNode("//ns:package/ns:metadata/ns:dependencies/ns:group/ns:dependency",$ns); + + $parentNode = $srcNode.parentNode; + $parentNode.RemoveAll(); + + + $ARCHES.Remove("arm64") + + foreach ($arch in $ARCHES) + { + $clone = $srcNode.CloneNode($true); + $clone.SetAttribute("id","cef.redist." + $arch); + $parentNode.AppendChild( $clone ) | Out-Null; + + + } + + if ( $parentNode.get_HasChildNodes() -eq $false ) + { + $parentNode.AppendChild( $srcNode ); # we need to keep one node on there as it is used as a template, for building other arches this group is ignored anyway + } + + $CefSharpNugetXml.Save( $nuspecFile ) +} + +UpdateNupsecCommonArches + +function DownloadNuget() +{ + if(-not (Test-Path $nuget)) + { + $client = New-Object System.Net.WebClient; + $client.DownloadFile('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', $nuget); + } + + if(-not (Test-Path $nuget)) + { + Die "Please install nuget. More information available at: http://docs.nuget.org/docs/start-here/installing-nuget" + } +} +$WorkingDir = split-path -parent $MyInvocation.MyCommand.Definition +$nuget = Join-Path $WorkingDir .\nuget\NuGet.exe +DownloadNuget -$CefVersion = '100.0.12' -$CefSharpVersion = $CefVersion + "0" function RemoveEnsureNuGetPackageBuildImports { - param([Parameter(Position = 0, ValueFromPipeline = $true)][string] $FileName) + param([Parameter(Position = 0, ValueFromPipeline = $true)][string] $FileName) - $xml = [xml](Get-Content $FileName) - $target = $xml.Project.Target | Where-Object {$_."Name" -eq "EnsureNuGetPackageBuildImports"} + $xml = [xml](Get-Content $FileName) + $target = $xml.SelectSingleNode("//Project/Target[@Name='EnsureNuGetPackageBuildImports']"); if($target -ne $null) { @@ -27,7 +93,7 @@ $vcxprojFiles = @('CefSharp.Core.Runtime\CefSharp.Core.Runtime.vcxproj','CefShar foreach($file in $vcxprojFiles) { - ..\nuget update $file -Id cef.sdk -Version $CefVersion + . $nuget update $file -Id cef.sdk -Version $CefVersion RemoveEnsureNuGetPackageBuildImports (Resolve-Path $file) } @@ -36,11 +102,12 @@ $vcxprojFiles = @('CefSharp.Core.Runtime\CefSharp.Core.Runtime.netcore.vcxproj', foreach($file in $vcxprojFiles) { - ..\nuget update $file -Id cef.sdk -Version $CefVersion + . $nuget update $file -Id cef.sdk -Version $CefVersion RemoveEnsureNuGetPackageBuildImports (Resolve-Path $file) } + #Read the newly updated version number from the packages.CefSharp.Core.Runtime.config $CefSharpCorePackagesXml = [xml](Get-Content (Resolve-Path 'CefSharp.Core.Runtime\packages.CefSharp.Core.Runtime.config')) @@ -52,16 +119,16 @@ $csprojFiles = @('CefSharp.WinForms.Example\CefSharp.WinForms.Example.netcore.cs foreach($file in $csprojFiles) { - $file = Resolve-Path $file + $file = Resolve-Path $file $xml = New-Object xml $xml.PreserveWhitespace = $true $xml.Load($file) - - $packRef = $xml.Project.ItemGroup.PackageReference | Where-Object {$_."Include" -eq "chromiumembeddedframework.runtime"} - + + $packRef = $xml.SelectSingleNode("//Project/ItemGroup/PackageReference[@Include='chromiumembeddedframework.runtime']"); $packRef.Version = $RedistVersion + $xml.Save( $file ) } -.\build.ps1 -Target update-build-version -Version $CefSharpVersion -AssemblyVersion $CefSharpVersion \ No newline at end of file +.\build.ps1 -Target update-build-version -Version $CefSharpVersion -AssemblyVersion $CefSharpVersion