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