Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use root xmlns (backport #297) #298

Merged
merged 11 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Build - CI
run: |
$adjustedPackageVersion="${{ steps.gitversion.outputs.semVer }}".ToLower();
dotnet pack -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} -o .\artifacts src/Resizetizer/src/Resizetizer.csproj
dotnet pack -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} -o .\artifacts src/Resizetizer/src/Resizetizer.csproj

- name: Upload Artifacts
uses: actions/upload-artifact@v4
Expand All @@ -72,7 +72,7 @@ jobs:

- name: Run UnitTests
run: |
dotnet test src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj
dotnet test src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} --logger GitHubActions --blame-crash --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover

validation_5_2:
name: Validate 5.2 Samples
Expand Down
2 changes: 1 addition & 1 deletion src/.nuspec/Uno.Resizetizer.windows.skia.targets
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</Target>

<Target
Name="GenerateUnoSplashWindowsSkia"
Name="GenerateUnoSplashWindowsSkia"
BeforeTargets="ProcessUnoSplashScreens"
Condition="'$(DesignTimeBuild)' != 'True' And '@(UnoSplashScreen)' != ''"
Outputs="$(_UnoSplashStampFile)">
Expand Down
55 changes: 35 additions & 20 deletions src/Resizetizer/src/GeneratePackageAppxManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;

namespace Uno.Resizetizer
Expand All @@ -15,9 +16,9 @@ public class GeneratePackageAppxManifest_v0 : Task
const string PackageVersionPlaceholder = "0.0.0.0";
const string ImageExtension = ".png";

const string ErrorVersionNumberCombination = "ApplicationDisplayVersion '{0}' was not a valid 3 part semver version number and/or ApplicationVersion '{1}' was not a valid integer.";
const string UapNamespace = "http://schemas.microsoft.com/appx/manifest/uap/windows10";

static readonly XNamespace xmlnsUap = "http://schemas.microsoft.com/appx/manifest/uap/windows10";
const string ErrorVersionNumberCombination = "ApplicationDisplayVersion '{0}' was not a valid 3 part semver version number and/or ApplicationVersion '{1}' was not a valid integer.";

[Required]
public string IntermediateOutputPath { get; set; } = null!;
Expand Down Expand Up @@ -91,7 +92,17 @@ public override bool Execute()

UpdateManifest(appx);

appx.Save(writer);
// Define the settings for the XmlWriter
var settings = new XmlWriterSettings
{
Indent = true,
Encoding = writer.Encoding,
NamespaceHandling = NamespaceHandling.OmitDuplicates,
OmitXmlDeclaration = false // Ensure the XML declaration is included
};

using var xmlWriter = XmlWriter.Create(writer, settings);
appx.Save(xmlWriter);
});

GeneratedAppxManifest = new TaskItem(filename);
Expand All @@ -109,6 +120,10 @@ void UpdateManifest(XDocument appx)
var appIconInfo = AppIcon?.Length > 0 ? ResizeImageInfo.Parse(AppIcon[0]) : null;
var splashInfo = SplashScreen?.Length > 0 ? ResizeImageInfo.Parse(SplashScreen[0]) : null;

var xmlnsUap = appx.Root.Attributes()
.Where(a => a.IsNamespaceDeclaration && a.Value == UapNamespace)
.Select(a => XNamespace.Get(a.Value))
.FirstOrDefault();
var xmlns = appx.Root!.GetDefaultNamespace();

// <Identity Name="" Version="" />
Expand Down Expand Up @@ -498,19 +513,19 @@ private static void SetDependencyTargetDeviceFamily(XDocument appx, string targe
if (targetDeviceFamilyElements is null || !targetDeviceFamilyElements.Any())
{
var universal = new XElement(xmlns + "TargetDeviceFamily");
universal.SetAttributeValue(xmlns + "Name", "Windows.Universal");
universal.SetAttributeValue("Name", "Windows.Universal");

var desktop = new XElement(xmlns + "TargetDeviceFamily");
desktop.SetAttributeValue(xmlns + "Name", "Windows.Desktop");
desktop.SetAttributeValue("Name", "Windows.Desktop");

dependencies.Add(universal, desktop);
targetDeviceFamilyElements = [universal, desktop];
}

foreach (var target in targetDeviceFamilyElements)
{
SetVersion(target, xmlns + "MinVersion", targetPlatformMinVersion);
SetVersion(target, xmlns + "MaxVersionTested", targetPlatformVersion);
SetVersion(target, "MinVersion", targetPlatformMinVersion);
SetVersion(target, "MaxVersionTested", targetPlatformVersion);
}
}

Expand All @@ -523,19 +538,19 @@ private static void SetVersion(XElement target, XName attributeName, string vers
}
}

static bool IsVersionAttribute(XAttribute attribute, XName attributeName)
{
var currentAttributeName = attribute.Name.LocalName;
var expectedAttributeName = attributeName.LocalName;
var currentAttributeNamespace = attribute.Name.Namespace.NamespaceName;
var expectedAttributeNamespace = attributeName.NamespaceName;
// The Version may not have a current Namespace and should use the default namespace
if (string.IsNullOrEmpty(currentAttributeNamespace))
return currentAttributeName == expectedAttributeName;
return currentAttributeName == expectedAttributeName && currentAttributeNamespace == expectedAttributeNamespace;
static bool IsVersionAttribute(XAttribute attribute, XName attributeName)
{
var currentAttributeName = attribute.Name.LocalName;
var expectedAttributeName = attributeName.LocalName;

var currentAttributeNamespace = attribute.Name.Namespace.NamespaceName;
var expectedAttributeNamespace = attributeName.NamespaceName;

// The Version may not have a current Namespace and should use the default namespace
if (string.IsNullOrEmpty(currentAttributeNamespace))
return currentAttributeName == expectedAttributeName;

return currentAttributeName == expectedAttributeName && currentAttributeNamespace == expectedAttributeNamespace;
}

public static bool TryMergeVersionNumbers(string? displayVersion, string? version, out string? finalVersion)
Expand Down
Loading