From aecff401f974f603cb78b8a665000b2a93490e80 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 5 Apr 2020 21:27:11 +1000 Subject: Modernize NetfxCompiler and table definitions. --- src/wixext/NetFxCompiler.cs | 12 ++++----- src/wixext/NetfxTableDefinitions.cs | 29 ++++++++++++++++++++++ .../NetfxWindowsInstallerBackendExtension.cs | 18 +------------- 3 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 src/wixext/NetfxTableDefinitions.cs (limited to 'src/wixext') diff --git a/src/wixext/NetFxCompiler.cs b/src/wixext/NetFxCompiler.cs index 4916994e..58c8c0f6 100644 --- a/src/wixext/NetFxCompiler.cs +++ b/src/wixext/NetFxCompiler.cs @@ -53,14 +53,14 @@ namespace WixToolset.Netfx /// The file identifier of the parent element. private void ParseNativeImageElement(Intermediate intermediate, IntermediateSection section, XElement element, string fileId) { - SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); Identifier id = null; string appBaseDirectory = null; string assemblyApplication = null; int attributes = 0x8; // 32bit is on by default int priority = 3; - foreach (XAttribute attrib in element.Attributes()) + foreach (var attrib in element.Attributes()) { if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) { @@ -75,7 +75,7 @@ namespace WixToolset.Netfx // See if a formatted value is specified. if (-1 == appBaseDirectory.IndexOf("[", StringComparison.Ordinal)) { - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "Directory", appBaseDirectory); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.Directory, appBaseDirectory); } break; case "AssemblyApplication": @@ -84,7 +84,7 @@ namespace WixToolset.Netfx // See if a formatted value is specified. if (-1 == assemblyApplication.IndexOf("[", StringComparison.Ordinal)) { - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "File", assemblyApplication); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.File, assemblyApplication); } break; case "Debug": @@ -140,7 +140,7 @@ namespace WixToolset.Netfx if (null == id) { - this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); + id = this.ParseHelper.CreateIdentifier("nni", fileId); } this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); @@ -149,7 +149,7 @@ namespace WixToolset.Netfx if (!this.Messaging.EncounteredError) { - section.Tuples.Add(new NetFxNativeImageTuple(sourceLineNumbers, id) + section.AddTuple(new NetFxNativeImageTuple(sourceLineNumbers, id) { FileRef = fileId, Priority = priority, diff --git a/src/wixext/NetfxTableDefinitions.cs b/src/wixext/NetfxTableDefinitions.cs new file mode 100644 index 00000000..378f6def --- /dev/null +++ b/src/wixext/NetfxTableDefinitions.cs @@ -0,0 +1,29 @@ +// 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 WixToolset.Netfx +{ + using WixToolset.Data.WindowsInstaller; + + public static class NetfxTableDefinitions + { + public static readonly TableDefinition NetFxNativeImage = new TableDefinition( + "Wix4NetFxNativeImage", + new[] + { + new ColumnDefinition("Wix4NetFxNativeImage", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The primary key, a non-localized token.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("File_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "File", keyColumn: 1, description: "The assembly for which a native image will be generated.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("Priority", ColumnType.Number, 2, primaryKey: false, nullable: false, ColumnCategory.Integer, minValue: 0, maxValue: 3, description: "The priority for generating this native image: 0 is syncronous, 1-3 represent various levels of queued generation."), + new ColumnDefinition("Attributes", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Integer, minValue: 0, maxValue: 2147483647, description: "Integer containing bit flags representing native image attributes."), + new ColumnDefinition("File_Application", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "The application which loads this assembly.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("Directory_ApplicationBase", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "The directory containing the application which loads this assembly.", modularizeType: ColumnModularizeType.Column), + }, + tupleDefinitionName: "NetFxNativeImage", + tupleIdIsPrimaryKey: true + ); + + public static readonly TableDefinition[] All = new[] + { + NetFxNativeImage, + }; + } +} diff --git a/src/wixext/NetfxWindowsInstallerBackendExtension.cs b/src/wixext/NetfxWindowsInstallerBackendExtension.cs index 7e30d396..e1404c1a 100644 --- a/src/wixext/NetfxWindowsInstallerBackendExtension.cs +++ b/src/wixext/NetfxWindowsInstallerBackendExtension.cs @@ -8,22 +8,6 @@ namespace WixToolset.Netfx public class NetfxWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension { - private static readonly TableDefinition[] Tables = new[] { - new TableDefinition( - "Wix4NetFxNativeImage", - "NetFxNativeImage", - new[] - { - new ColumnDefinition("Wix4NetFxNativeImage", ColumnType.String, 72, true, false, ColumnCategory.Identifier, description: "The primary key, a non-localized token."), - new ColumnDefinition("File_", ColumnType.String, 0, false, false, ColumnCategory.Identifier, keyTable:"File", keyColumn: 1, description: "The assembly for which a native image will be generated."), - new ColumnDefinition("Priority", ColumnType.Number, 2, false, false, ColumnCategory.Integer, maxValue: 3, description: "The priority for generating this native image: 0 is syncronous, 1-3 represent various levels of queued generation."), - new ColumnDefinition("Attributes", ColumnType.Number, 4, false, false, ColumnCategory.Integer, maxValue: 2147483647, description: "Integer containing bit flags representing native image attributes."), - new ColumnDefinition("File_Application", ColumnType.String, 72, false, true, ColumnCategory.Formatted, description: "The application which loads this assembly."), - new ColumnDefinition("Directory_ApplicationBase", ColumnType.String, 72, false, true, ColumnCategory.Formatted, description: "The directory containing the application which loads this assembly."), - } - ), - }; - - public override IEnumerable TableDefinitions { get => Tables; } + public override IEnumerable TableDefinitions => NetfxTableDefinitions.All; } } -- cgit v1.2.3-55-g6feb