2 // AL.cs: Task for assembly linker
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Diagnostics;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Utilities;
35 using Mono.XBuild.Utilities;
37 namespace Microsoft.Build.Tasks {
38 public class AL : ToolTaskExtension {
45 protected internal override void AddResponseFileCommands (
46 CommandLineBuilderExtension commandLine)
48 commandLine.AppendSwitchIfNotNull ("/algid:", AlgorithmId);
49 commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
50 commandLine.AppendSwitchIfNotNull ("/company:", CompanyName);
51 commandLine.AppendSwitchIfNotNull ("/configuration:", Configuration);
52 commandLine.AppendSwitchIfNotNull ("/culture:", Culture);
53 commandLine.AppendSwitchIfNotNull ("/copyright:", Copyright);
54 if (Bag ["DelaySign"] != null)
56 commandLine.AppendSwitch ("/delaysign+");
58 commandLine.AppendSwitch ("/delaysign-");
59 commandLine.AppendSwitchIfNotNull ("/description:", Description);
60 if (EmbedResources != null) {
61 foreach (ITaskItem item in EmbedResources) {
62 string logical_name = item.GetMetadata ("LogicalName");
63 if (!string.IsNullOrEmpty (logical_name))
64 commandLine.AppendSwitchIfNotNull ("/embed:", string.Format ("{0},{1}", item.ItemSpec, logical_name));
66 commandLine.AppendSwitchIfNotNull ("/embed:", item.ItemSpec);
69 commandLine.AppendSwitchIfNotNull ("/evidence:", EvidenceFile);
70 commandLine.AppendSwitchIfNotNull ("/fileversion:", FileVersion);
71 commandLine.AppendSwitchIfNotNull ("/flags:", Flags);
72 if (GenerateFullPaths)
73 commandLine.AppendSwitch ("/fullpaths");
74 commandLine.AppendSwitchIfNotNull ("/keyname:", KeyContainer);
75 commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
76 if (LinkResources != null)
77 foreach (ITaskItem item in LinkResources)
78 commandLine.AppendSwitchIfNotNull ("/link:", item.ItemSpec);
79 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
80 if (OutputAssembly != null)
81 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
83 commandLine.AppendSwitchIfNotNull ("/product:", ProductName);
84 commandLine.AppendSwitchIfNotNull ("/productversion:", ProductVersion);
85 if (ResponseFiles != null)
86 foreach (string s in ResponseFiles)
87 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", s));
88 if (SourceModules != null)
89 foreach (ITaskItem item in SourceModules)
90 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
91 commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
92 commandLine.AppendSwitchIfNotNull ("/template:", TemplateFile);
93 commandLine.AppendSwitchIfNotNull ("/title:", Title);
94 commandLine.AppendSwitchIfNotNull ("/trademark:", Trademark);
95 commandLine.AppendSwitchIfNotNull ("/version:", Version);
96 commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
97 commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
100 public override bool Execute ()
102 return base.Execute ();
105 protected override string GenerateFullPathToTool ()
107 if (!string.IsNullOrEmpty (ToolPath))
108 return Path.Combine (ToolPath, ToolExe);
109 return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
112 public string AlgorithmId {
113 get { return (string) Bag ["AlgorithmId"]; }
114 set { Bag ["AlgorithmId"] = value; }
117 public string BaseAddress {
118 get { return (string) Bag ["BaseAddress"]; }
119 set { Bag ["BaseAddress"] = value; }
122 public string CompanyName {
123 get { return (string) Bag ["CompanyName"]; }
124 set { Bag ["CompanyName"] = value; }
127 public string Configuration {
128 get { return (string) Bag ["Configuration"]; }
129 set { Bag ["Configuration"] = value; }
132 public string Copyright {
133 get { return (string) Bag ["Copyright"]; }
134 set { Bag ["Copyright"] = value; }
137 public string Culture {
138 get { return (string) Bag ["Culture"]; }
139 set { Bag ["Culture"] = value; }
142 public bool DelaySign {
143 get { return GetBoolParameterWithDefault ("DelaySign", false); }
144 set { Bag ["DelaySign"] = value; }
147 public string Description {
148 get { return (string) Bag ["Description"]; }
149 set { Bag ["Description"] = value; }
152 public ITaskItem[] EmbedResources {
153 get { return (ITaskItem[]) Bag ["EmbedResources"]; }
154 set { Bag ["EmbedResources"] = value; }
157 public string EvidenceFile {
158 get { return (string) Bag ["EvidenceFile"]; }
159 set { Bag ["EvidenceFile"] = value; }
162 public string FileVersion {
163 get { return (string) Bag ["FileVersion"]; }
164 set { Bag ["FileVersion"] = value; }
167 public string Flags {
168 get { return (string) Bag ["Flags"]; }
169 set { Bag ["Flags"] = value; }
172 public bool GenerateFullPaths {
173 get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
174 set { Bag ["GenerateFullPaths"] = value; }
177 public string KeyContainer {
178 get { return (string) Bag ["KeyContainer"]; }
179 set { Bag ["KeyContainer"] = value; }
182 public string KeyFile {
183 get { return (string) Bag ["KeyFile"]; }
184 set { Bag ["KeyFile"] = value; }
187 public ITaskItem[] LinkResources {
188 get { return (ITaskItem[]) Bag ["LinkResources"]; }
189 set { Bag ["LinkResources"] = value; }
192 public string MainEntryPoint {
193 get { return (string) Bag ["MainEntryPoint"]; }
194 set { Bag ["MainEntryPoint"] = value; }
199 public ITaskItem OutputAssembly {
200 get { return (ITaskItem) Bag ["OutputAssembly"]; }
201 set { Bag ["OutputAssembly"] = value; }
204 public string Platform {
205 get { return (string) Bag ["Platform"]; }
206 set { Bag ["Platform"] = value; }
209 public string ProductName {
210 get { return (string) Bag ["ProductName"]; }
211 set { Bag ["ProductName"] = value; }
214 public string ProductVersion {
215 get { return (string) Bag ["ProductVersion"]; }
216 set { Bag ["ProductVersion"] = value; }
219 public string[] ResponseFiles {
220 get { return (string[]) Bag ["ResponseFiles"]; }
221 set { Bag ["ResponseFiles"] = value; }
224 public ITaskItem[] SourceModules {
225 get { return (ITaskItem[]) Bag ["SourceModules"]; }
226 set { Bag ["SourceModules"] = value; }
229 public string TargetType {
230 get { return (string) Bag ["TargetType"]; }
231 set { Bag ["TargetType"] = value; }
234 public string TemplateFile {
235 get { return (string) Bag ["TemplateFile"]; }
236 set { Bag ["TemplateFile"] = value; }
239 public string Title {
240 get { return (string) Bag ["Title"]; }
241 set { Bag ["Title"] = value; }
244 protected override string ToolName {
245 get { return "al.exe"; }
248 public string Trademark {
249 get { return (string) Bag ["Trademark"]; }
250 set { Bag ["Trademark"] = value; }
253 public string Version {
254 get { return (string) Bag ["Version"]; }
255 set { Bag ["Version"] = value; }
258 public string Win32Icon {
259 get { return (string) Bag ["Win32Icon"]; }
260 set { Bag ["Win32Icon"] = value; }
263 public string Win32Resource {
264 get { return (string) Bag ["Win32Resource"]; }
265 set { Bag ["Win32Resource"] = value; }