From 4e497844f15a116082a129a84be48a2c10ce3c31 Mon Sep 17 00:00:00 2001 From: Timotei Dolean Date: Thu, 25 Apr 2019 15:55:07 +0300 Subject: [PATCH] Handle versions in XAML paths --- ILRepack.Tests/Steps/XamlResourcePathPatcherStepTests.cs | 8 ++++++++ ILRepack/Steps/XamlResourcePathPatcherStep.cs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/ILRepack.Tests/Steps/XamlResourcePathPatcherStepTests.cs b/ILRepack.Tests/Steps/XamlResourcePathPatcherStepTests.cs index 4be3d11a..7e5f9b33 100644 --- a/ILRepack.Tests/Steps/XamlResourcePathPatcherStepTests.cs +++ b/ILRepack.Tests/Steps/XamlResourcePathPatcherStepTests.cs @@ -69,6 +69,14 @@ private IEnumerable GetMainAssemblyPatchPathTestData() "/ClassLibrary;component/ButtonStyles.xaml", "/MainAssembly;component/ClassLibrary/ButtonStyles.xaml"), + new TestCaseData( + "/ClassLibrary;V2.0.0;component/ButtonStyles.xaml", + "/MainAssembly;component/ClassLibrary/ButtonStyles.xaml"), + + new TestCaseData( + "/ClassLibrary;v2.0.0;component/ButtonStyles.xaml", + "/MainAssembly;component/ClassLibrary/ButtonStyles.xaml"), + new TestCaseData( "/themes/ButtonStyles.xaml", "/themes/ButtonStyles.xaml"), diff --git a/ILRepack/Steps/XamlResourcePathPatcherStep.cs b/ILRepack/Steps/XamlResourcePathPatcherStep.cs index cd6e9d2e..1d7dff5c 100644 --- a/ILRepack/Steps/XamlResourcePathPatcherStep.cs +++ b/ILRepack/Steps/XamlResourcePathPatcherStep.cs @@ -17,6 +17,7 @@ using Mono.Cecil.Cil; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; namespace ILRepacking.Steps { @@ -25,6 +26,7 @@ internal class XamlResourcePathPatcherStep : IRepackStep { private readonly ILogger _logger; private readonly IRepackContext _repackContext; + private static readonly Regex VersionRegex = new Regex("v(.?\\d)+;", RegexOptions.IgnoreCase); public XamlResourcePathPatcherStep(ILogger logger, IRepackContext repackContext) { @@ -147,6 +149,11 @@ internal static string PatchPath( private static bool TryPatchPath( string path, AssemblyDefinition primaryAssembly, AssemblyDefinition referenceAssembly, out string patchedPath) { + // get rid of potential versions in the path + // Starting with a new .NET MSBuild version, in case the project is built + // via a new-format .csproj, the version is appended + path = VersionRegex.Replace(path, string.Empty); + string referenceAssemblyPath = GetAssemblyPath(referenceAssembly); string newPath = GetAssemblyPath(primaryAssembly) + "/" + referenceAssembly.Name.Name;