Skip to content

Commit

Permalink
UpdateNugetPackages takes parameters and fixes common.nuspec requirem…
Browse files Browse the repository at this point in the history
…ents based on arch
  • Loading branch information
mitchcapper authored and amaitland committed Apr 20, 2022
1 parent 837f6ec commit cfa5b41
Showing 1 changed file with 79 additions and 12 deletions.
91 changes: 79 additions & 12 deletions UpdateNugetPackages.ps1
Original file line number Diff line number Diff line change
@@ -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)
{
Expand All @@ -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)
}
Expand All @@ -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'))
Expand All @@ -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
.\build.ps1 -Target update-build-version -Version $CefSharpVersion -AssemblyVersion $CefSharpVersion

0 comments on commit cfa5b41

Please sign in to comment.