diff options
Diffstat (limited to 'src/ext/NetFx/wixext/NetFxCompiler.cs')
-rw-r--r-- | src/ext/NetFx/wixext/NetFxCompiler.cs | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/ext/NetFx/wixext/NetFxCompiler.cs b/src/ext/NetFx/wixext/NetFxCompiler.cs new file mode 100644 index 00000000..90aa8bcb --- /dev/null +++ b/src/ext/NetFx/wixext/NetFxCompiler.cs | |||
@@ -0,0 +1,163 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset.Netfx | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Xml.Linq; | ||
8 | using WixToolset.Data; | ||
9 | using WixToolset.Extensibility; | ||
10 | using WixToolset.Extensibility.Data; | ||
11 | using WixToolset.Netfx.Symbols; | ||
12 | |||
13 | /// <summary> | ||
14 | /// The compiler for the WiX Toolset .NET Framework Extension. | ||
15 | /// </summary> | ||
16 | public sealed class NetfxCompiler : BaseCompilerExtension | ||
17 | { | ||
18 | public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/netfx"; | ||
19 | |||
20 | /// <summary> | ||
21 | /// Processes an element for the Compiler. | ||
22 | /// </summary> | ||
23 | /// <param name="parentElement">Parent element of element to process.</param> | ||
24 | /// <param name="element">Element to process.</param> | ||
25 | /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param> | ||
26 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) | ||
27 | { | ||
28 | switch (parentElement.Name.LocalName) | ||
29 | { | ||
30 | case "File": | ||
31 | string fileId = context["FileId"]; | ||
32 | |||
33 | switch (element.Name.LocalName) | ||
34 | { | ||
35 | case "NativeImage": | ||
36 | this.ParseNativeImageElement(intermediate, section, element, fileId); | ||
37 | break; | ||
38 | default: | ||
39 | this.ParseHelper.UnexpectedElement(parentElement, element); | ||
40 | break; | ||
41 | } | ||
42 | break; | ||
43 | default: | ||
44 | this.ParseHelper.UnexpectedElement(parentElement, element); | ||
45 | break; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | /// <summary> | ||
50 | /// Parses a NativeImage element. | ||
51 | /// </summary> | ||
52 | /// <param name="element">The element to parse.</param> | ||
53 | /// <param name="fileId">The file identifier of the parent element.</param> | ||
54 | private void ParseNativeImageElement(Intermediate intermediate, IntermediateSection section, XElement element, string fileId) | ||
55 | { | ||
56 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | ||
57 | Identifier id = null; | ||
58 | string appBaseDirectory = null; | ||
59 | string assemblyApplication = null; | ||
60 | int attributes = 0x8; // 32bit is on by default | ||
61 | int priority = 3; | ||
62 | |||
63 | foreach (var attrib in element.Attributes()) | ||
64 | { | ||
65 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | ||
66 | { | ||
67 | switch (attrib.Name.LocalName) | ||
68 | { | ||
69 | case "Id": | ||
70 | id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); | ||
71 | break; | ||
72 | case "AppBaseDirectory": | ||
73 | appBaseDirectory = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
74 | |||
75 | // See if a formatted value is specified. | ||
76 | if (-1 == appBaseDirectory.IndexOf("[", StringComparison.Ordinal)) | ||
77 | { | ||
78 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.Directory, appBaseDirectory); | ||
79 | } | ||
80 | break; | ||
81 | case "AssemblyApplication": | ||
82 | assemblyApplication = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
83 | |||
84 | // See if a formatted value is specified. | ||
85 | if (-1 == assemblyApplication.IndexOf("[", StringComparison.Ordinal)) | ||
86 | { | ||
87 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.File, assemblyApplication); | ||
88 | } | ||
89 | break; | ||
90 | case "Debug": | ||
91 | if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib)) | ||
92 | { | ||
93 | attributes |= 0x1; | ||
94 | } | ||
95 | break; | ||
96 | case "Dependencies": | ||
97 | if (YesNoType.No == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib)) | ||
98 | { | ||
99 | attributes |= 0x2; | ||
100 | } | ||
101 | break; | ||
102 | case "Platform": | ||
103 | string platformValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
104 | if (0 < platformValue.Length) | ||
105 | { | ||
106 | switch (platformValue) | ||
107 | { | ||
108 | case "32bit": | ||
109 | // 0x8 is already on by default | ||
110 | break; | ||
111 | case "64bit": | ||
112 | attributes &= ~0x8; | ||
113 | attributes |= 0x10; | ||
114 | break; | ||
115 | case "all": | ||
116 | attributes |= 0x10; | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | break; | ||
121 | case "Priority": | ||
122 | priority = this.ParseHelper.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, 3); | ||
123 | break; | ||
124 | case "Profile": | ||
125 | if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib)) | ||
126 | { | ||
127 | attributes |= 0x4; | ||
128 | } | ||
129 | break; | ||
130 | default: | ||
131 | this.ParseHelper.UnexpectedAttribute(element, attrib); | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | if (null == id) | ||
142 | { | ||
143 | id = this.ParseHelper.CreateIdentifier("nni", fileId); | ||
144 | } | ||
145 | |||
146 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); | ||
147 | |||
148 | this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "Wix4NetFxScheduleNativeImage", this.Context.Platform, CustomActionPlatforms.ARM64 | CustomActionPlatforms.X64 | CustomActionPlatforms.X86); | ||
149 | |||
150 | if (!this.Messaging.EncounteredError) | ||
151 | { | ||
152 | section.AddSymbol(new NetFxNativeImageSymbol(sourceLineNumbers, id) | ||
153 | { | ||
154 | FileRef = fileId, | ||
155 | Priority = priority, | ||
156 | Attributes = attributes, | ||
157 | ApplicationFileRef = assemblyApplication, | ||
158 | ApplicationBaseDirectoryRef = appBaseDirectory, | ||
159 | }); | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | } | ||