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

Raise conversion warning for After and Before attributes #591

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions src/wix/WixToolset.Converters/WixConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public sealed class WixConverter
{ "WixSchedHttpUrlReservationsInstall", "Wix4SchedHttpUrlReservationsInstall_<PlatformSuffix>" },
{ "ConfigureIIs", "Wix4ConfigureIIs_<PlatformSuffix>" },
{ "UninstallCertificates", "Wix4UninstallCertificates_<PlatformSuffix>" },
{ "InstallCertificates", "Wix4_<PlatformSuffix>" },
{ "InstallCertificates", "Wix4InstallCertificates_<PlatformSuffix>" },
{ "MessageQueuingUninstall", "Wix4MessageQueuingUninstall_<PlatformSuffix>" },
{ "MessageQueuingInstall", "Wix4_MessageQueuingInstall<PlatformSuffix>" },
{ "NetFxScheduleNativeImage", "Wix4NetFxScheduleNativeImage_<PlatformSuffix>" },
Expand Down Expand Up @@ -914,13 +914,18 @@ private void ConvertColumnElement(XElement element)

private void ConvertCustomElement(XElement element)
{
var actionId = element.Attribute("Action")?.Value;
var attributes = new string[] { "Action", "After", "Before" };

if (actionId != null
&& CustomActionIdsWithPlatformSuffix.TryGetValue(actionId, out var replacementId))
foreach (var attribute in attributes)
{
this.OnError(ConverterTestType.CustomActionIdsIncludePlatformSuffix, element,
$"Custom action ids have changed in WiX v4 extensions to support platform-specific custom actions. The platform is applied as a suffix: _X86, _X64, _A64 (Arm64). When manually rescheduling custom action '{actionId}', you must use the new custom action id '{replacementId}'. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages");
var attributeValue = element.Attribute(attribute)?.Value;

if (attributeValue != null
&& CustomActionIdsWithPlatformSuffix.TryGetValue(attributeValue, out var replacementId))
{
this.OnError(ConverterTestType.CustomActionIdsIncludePlatformSuffix, element,
$"Custom action ids have changed in WiX v4 extensions to support platform-specific custom actions. The platform is applied as a suffix: _X86, _X64, _A64 (Arm64). When manually rescheduling custom action '{attributeValue}', you must use the new custom action id '{replacementId}'. See the conversion FAQ for more information: https://wixtoolset.org/docs/fourthree/faqs/#converting-packages");
}
}
}

Expand Down Expand Up @@ -1830,6 +1835,7 @@ private void ConvertSequenceElement(XElement element)
{
foreach (var child in element.Elements())
{
this.ConvertCustomActionElement(child);
this.ConvertInnerTextToAttribute(child, "Condition");
}
}
Expand All @@ -1846,6 +1852,7 @@ private void ConvertSetDirectoryElement(XElement element)

private void ConvertSetPropertyElement(XElement element)
{
this.ConvertCustomElement(element);
this.ConvertInnerTextToAttribute(element, "Condition");
}

Expand Down
35 changes: 35 additions & 0 deletions src/wix/test/WixToolsetTest.Converters/SequenceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,40 @@ public void FixCondition()
var actualLines = UnformattedDocumentLines(document);
WixAssert.CompareLineByLine(expected, actualLines);
}

[Fact]
public void FixConditionWixCa()
{
var parse = String.Join(Environment.NewLine,
"<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
" <Fragment>",
" <InstallUISequence>",
" <Custom Action='ExampleCA' After='WixQueryOsDirs'>NOT Installed</Custom>",
" </InstallUISequence>",
" </Fragment>",
"</Wix>");

var expected = new[]
{
"<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
" <Fragment>",
" <InstallUISequence>",
" <Custom Action=\"ExampleCA\" After=\"WixQueryOsDirs\" Condition=\"NOT Installed\" />",
" </InstallUISequence>",
" </Fragment>",
"</Wix>"
};

var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);

var messaging = new MockMessaging();
var converter = new WixConverter(messaging, 2, null, null);

var errors = converter.ConvertDocument(document);
Assert.Equal(3, errors);

var actualLines = UnformattedDocumentLines(document);
WixAssert.CompareLineByLine(expected, actualLines);
}
}
}
47 changes: 47 additions & 0 deletions src/wix/test/WixToolsetTest.Converters/SetPropertyFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolsetTest.Converters
{
using System;
using System.Xml.Linq;
using WixInternal.TestSupport;
using WixToolset.Converters;
using WixToolsetTest.Converters.Mocks;
using Xunit;

public class SetPropertyFixture : BaseConverterFixture
{
[Fact]
public void FixConditionWixCa()
{
var parse = String.Join(Environment.NewLine,
"<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
" <Fragment>",
" <SetProperty Id='INSTALLFOLDER' ",
" After='WixQueryOsDirs'" +
" Value='test'>NOT Installed</SetProperty>",
" </Fragment>",
"</Wix>");

var expected = new[]
{
"<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
" <Fragment>",
" <SetProperty Id=\"INSTALLFOLDER\" After=\"WixQueryOsDirs\" Value=\"test\" Condition=\"NOT Installed\" />",
" </Fragment>",
"</Wix>"
};

var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);

var messaging = new MockMessaging();
var converter = new WixConverter(messaging, 2, null, null);

var errors = converter.ConvertDocument(document);
Assert.Equal(3, errors);

var actualLines = UnformattedDocumentLines(document);
WixAssert.CompareLineByLine(expected, actualLines);
}
}
}
Loading