Fix for added elements to reference platform-specific extension custom actions.

This commit is contained in:
Bob Arnson 2021-04-23 17:50:54 -04:00
Родитель b0840f6ad8
Коммит 0177cb5b9b
3 изменённых файлов: 189 добавлений и 2 удалений

Просмотреть файл

@ -105,6 +105,7 @@ namespace WixToolset.Converters
private static readonly XName PermissionExElementName = WixNamespace + "PermissionEx";
private static readonly XName ProductElementName = WixNamespace + "Product";
private static readonly XName ProgressTextElementName = WixNamespace + "ProgressText";
private static readonly XName PropertyRefElementName = WixNamespace + "PropertyRef";
private static readonly XName PublishElementName = WixNamespace + "Publish";
private static readonly XName ProvidesElementName = WixNamespace + "Provides";
private static readonly XName RequiresElementName = WixNamespace + "Requires";
@ -138,6 +139,7 @@ namespace WixToolset.Converters
private static readonly XName UtilRegistrySearchName = WixUtilNamespace + "RegistrySearch";
private static readonly XName UtilXmlConfigElementName = WixUtilNamespace + "XmlConfig";
private static readonly XName CustomActionElementName = WixNamespace + "CustomAction";
private static readonly XName CustomActionRefElementName = WixNamespace + "CustomActionRef";
private static readonly XName PropertyElementName = WixNamespace + "Property";
private static readonly XName Wix4ElementName = WixNamespace + "Wix";
private static readonly XName Wix3ElementName = Wix3Namespace + "Wix";
@ -230,12 +232,14 @@ namespace WixToolset.Converters
{ WixConverter.PermissionExElementName, this.ConvertPermissionExElement },
{ WixConverter.ProductElementName, this.ConvertProductElement },
{ WixConverter.ProgressTextElementName, this.ConvertProgressTextElement },
{ WixConverter.PropertyRefElementName, this.ConvertPropertyRefElement },
{ WixConverter.PublishElementName, this.ConvertPublishElement },
{ WixConverter.MultiStringValueElementName, this.ConvertMultiStringValueElement },
{ WixConverter.RegistryKeyElementName, this.ConvertRegistryKeyElement },
{ WixConverter.RegistrySearchElementName, this.ConvertRegistrySearchElement },
{ WixConverter.RemotePayloadElementName, this.ConvertRemotePayloadElement },
{ WixConverter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement },
{ WixConverter.CustomActionRefElementName, this.ConvertCustomActionRefElement },
{ WixConverter.ServiceArgumentElementName, this.ConvertServiceArgumentElement },
{ WixConverter.SetDirectoryElementName, this.ConvertSetDirectoryElement },
{ WixConverter.SetPropertyElementName, this.ConvertSetPropertyElement },
@ -1293,6 +1297,110 @@ namespace WixToolset.Converters
xAttribute?.Remove();
}
private void ConvertPropertyRefElement(XElement element)
{
var newElementName = String.Empty;
var id = element.Attribute("Id");
switch (id?.Value)
{
case "WIX_SUITE_BACKOFFICE":
case "WIX_SUITE_BLADE":
case "WIX_SUITE_COMMUNICATIONS":
case "WIX_SUITE_COMPUTE_SERVER":
case "WIX_SUITE_DATACENTER":
case "WIX_SUITE_EMBEDDED_RESTRICTED":
case "WIX_SUITE_EMBEDDEDNT":
case "WIX_SUITE_ENTERPRISE":
case "WIX_SUITE_MEDIACENTER":
case "WIX_SUITE_PERSONAL":
case "WIX_SUITE_SECURITY_APPLIANCE":
case "WIX_SUITE_SERVERR2":
case "WIX_SUITE_SINGLEUSERTS":
case "WIX_SUITE_SMALLBUSINESS":
case "WIX_SUITE_SMALLBUSINESS_RESTRICTED":
case "WIX_SUITE_STARTER":
case "WIX_SUITE_STORAGE_SERVER":
case "WIX_SUITE_TABLETPC":
case "WIX_SUITE_TERMINAL":
case "WIX_SUITE_WH_SERVER":
newElementName = "QueryWindowsSuiteInfo";
break;
case "WIX_DIR_ADMINTOOLS":
case "WIX_DIR_ALTSTARTUP":
case "WIX_DIR_CDBURN_AREA":
case "WIX_DIR_COMMON_ADMINTOOLS":
case "WIX_DIR_COMMON_ALTSTARTUP":
case "WIX_DIR_COMMON_DOCUMENTS":
case "WIX_DIR_COMMON_FAVORITES":
case "WIX_DIR_COMMON_MUSIC":
case "WIX_DIR_COMMON_PICTURES":
case "WIX_DIR_COMMON_VIDEO":
case "WIX_DIR_COOKIES":
case "WIX_DIR_DESKTOP":
case "WIX_DIR_HISTORY":
case "WIX_DIR_INTERNET_CACHE":
case "WIX_DIR_MYMUSIC":
case "WIX_DIR_MYPICTURES":
case "WIX_DIR_MYVIDEO":
case "WIX_DIR_NETHOOD":
case "WIX_DIR_PERSONAL":
case "WIX_DIR_PRINTHOOD":
case "WIX_DIR_PROFILE":
case "WIX_DIR_RECENT":
case "WIX_DIR_RESOURCES":
newElementName = "QueryWindowsDirectories";
break;
case "WIX_DWM_COMPOSITION_ENABLED":
case "WIX_WDDM_DRIVER_PRESENT":
newElementName = "QueryWindowsDriverInfo";
break;
case "WIX_ACCOUNT_LOCALSYSTEM":
case "WIX_ACCOUNT_LOCALSERVICE":
case "WIX_ACCOUNT_NETWORKSERVICE":
case "WIX_ACCOUNT_ADMINISTRATORS":
case "WIX_ACCOUNT_USERS":
case "WIX_ACCOUNT_GUESTS":
case "WIX_ACCOUNT_PERFLOGUSERS":
case "WIX_ACCOUNT_PERFLOGUSERS_NODOMAIN":
newElementName = "QueryWindowsWellKnownSIDs";
break;
}
if (!String.IsNullOrEmpty(newElementName)
&& this.OnError(ConverterTestType.UtilReferencesReplaced, element, "Custom action and property reference {0} to WixUtilExtension have been replaced with strongly-typed elements.", id))
{
element.AddAfterSelf(new XElement(WixUtilNamespace + newElementName));
element.Remove();
}
}
private void ConvertCustomActionRefElement(XElement element)
{
var newElementName = String.Empty;
var id = element.Attribute("Id");
switch (id?.Value)
{
case "WixBroadcastSettingChange":
case "WixBroadcastEnvironmentChange":
case "WixCheckRebootRequired":
case "WixExitEarlyWithSuccess":
case "WixFailWhenDeferred":
case "WixWaitForEvent":
case "WixWaitForEventDeferred":
newElementName = id?.Value.Substring(3); // strip leading Wix
break;
}
if (!String.IsNullOrEmpty(newElementName)
&& this.OnError(ConverterTestType.UtilReferencesReplaced, element, "Custom action and property reference {0} to WixUtilExtension have been replaced with strongly-typed elements.", id))
{
element.AddAfterSelf(new XElement(WixUtilNamespace + newElementName));
element.Remove();
}
}
private void ConvertPublishElement(XElement element)
{
this.ConvertInnerTextToAttribute(element, "Condition");
@ -2317,6 +2425,11 @@ namespace WixToolset.Converters
/// Standard directories should no longer be defined using the Directory element.
/// </summary>
DefiningStandardDirectoryDeprecated,
/// <summary>
/// Naked custom action and property references replaced with WixUtilExtension elements.
/// </summary>
UtilReferencesReplaced,
}
}
}

Просмотреть файл

@ -8,7 +8,6 @@ namespace WixToolsetTest.Converters
using WixBuildTools.TestSupport;
using WixToolset.Converters;
using WixToolset.Core;
using WixToolset.Core.ExtensibilityServices;
using WixToolset.Core.TestPackage;
using WixToolsetTest.Converters.Mocks;
using Xunit;
@ -88,7 +87,7 @@ namespace WixToolsetTest.Converters
var converter = new WixConverter(messaging, 4);
var errors = converter.ConvertFile(targetFile, true);
Assert.Equal(10, errors);
Assert.Single(messaging.Messages.Where(m => m.Id == 5/*WixConverter.ConverterTestType.UnauthorizedAccessException*/));
}
}

Просмотреть файл

@ -111,5 +111,80 @@ namespace WixToolsetTest.Converters
var actualLines = UnformattedDocumentLines(document);
WixAssert.CompareLineByLine(expected, actualLines);
}
[Fact]
public void FixXmlConfigValueCData()
{
var parse = String.Join(Environment.NewLine,
"<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>",
" <Fragment>",
" <util:XmlConfig Id='Change' ElementPath='book'>",
" <![CDATA[a<>b]]>",
" </util:XmlConfig>",
" </Fragment>",
"</Wix>");
var expected = new[]
{
"<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">",
" <Fragment>",
" <util:XmlConfig Id=\"Change\" ElementPath=\"book\" Value=\"a&lt;&gt;b\" />",
" </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);
}
[Fact]
public void FixQueryOsPropertyRefs()
{
var parse = String.Join(Environment.NewLine,
"<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>",
" <Fragment>",
" <PropertyRef Id=\"WIX_SUITE_ENTERPRISE\" />",
" <PropertyRef Id=\"WIX_DIR_COMMON_DOCUMENTS\" />",
" <CustomActionRef Id=\"WixFailWhenDeferred\" />",
" <UI>",
" <PropertyRef Id=\"WIX_ACCOUNT_LOCALSERVICE\" />",
" </UI>",
" </Fragment>",
"</Wix>");
var expected = new[]
{
"<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\" xmlns:util=\"http://wixtoolset.org/schemas/v4/wxs/util\">",
" <Fragment>",
" <util:QueryWindowsSuiteInfo />",
" <util:QueryWindowsDirectories />",
" <util:FailWhenDeferred />",
" <UI>",
" <util:QueryWindowsWellKnownSIDs />",
" </UI>",
" </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(6, errors);
var actualLines = UnformattedDocumentLines(document);
WixAssert.CompareLineByLine(expected, actualLines);
}
}
}