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