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.
30 using System.Diagnostics;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Utilities;
34 using Mono.XBuild.Utilities;
36 namespace Microsoft.Build.Tasks {
37 public class AL : ToolTaskExtension {
44 protected internal override void AddResponseFileCommands (
45 CommandLineBuilderExtension commandLine)
47 commandLine.AppendSwitchIfNotNull ("/algid:", AlgorithmId);
48 commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
49 commandLine.AppendSwitchIfNotNull ("/company:", CompanyName);
50 commandLine.AppendSwitchIfNotNull ("/configuration:", Configuration);
51 commandLine.AppendSwitchIfNotNull ("/culture:", Culture);
52 commandLine.AppendSwitchIfNotNull ("/copyright:", Copyright);
53 if (Bag ["DelaySign"] != null)
55 commandLine.AppendSwitch ("/delaysign+");
57 commandLine.AppendSwitch ("/delaysign-");
58 commandLine.AppendSwitchIfNotNull ("/description:", Description);
59 if (EmbedResources != null) {
60 foreach (ITaskItem item in EmbedResources) {
61 string logical_name = item.GetMetadata ("LogicalName");
62 if (!string.IsNullOrEmpty (logical_name))
63 commandLine.AppendSwitchIfNotNull ("/embed:", string.Format ("{0},{1}", item.ItemSpec, logical_name));
65 commandLine.AppendSwitchIfNotNull ("/embed:", item.ItemSpec);
68 commandLine.AppendSwitchIfNotNull ("/evidence:", EvidenceFile);
69 commandLine.AppendSwitchIfNotNull ("/fileversion:", FileVersion);
70 commandLine.AppendSwitchIfNotNull ("/flags:", Flags);
71 if (GenerateFullPaths)
72 commandLine.AppendSwitch ("/fullpaths");
73 commandLine.AppendSwitchIfNotNull ("/keyname:", KeyContainer);
74 commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
75 if (LinkResources != null)
76 foreach (ITaskItem item in LinkResources)
77 commandLine.AppendSwitchIfNotNull ("/link:", item.ItemSpec);
78 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
79 if (OutputAssembly != null)
80 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
82 commandLine.AppendSwitchIfNotNull ("/product:", ProductName);
83 commandLine.AppendSwitchIfNotNull ("/productversion:", ProductVersion);
84 if (ResponseFiles != null)
85 foreach (string s in ResponseFiles)
86 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", s));
87 if (SourceModules != null)
88 foreach (ITaskItem item in SourceModules)
89 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
90 commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
91 commandLine.AppendSwitchIfNotNull ("/template:", TemplateFile);
92 commandLine.AppendSwitchIfNotNull ("/title:", Title);
93 commandLine.AppendSwitchIfNotNull ("/trademark:", Trademark);
94 commandLine.AppendSwitchIfNotNull ("/version:", Version);
95 commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
96 commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
99 public override bool Execute ()
101 return base.Execute ();
104 protected override string GenerateFullPathToTool ()
106 if (!string.IsNullOrEmpty (ToolPath))
107 return Path.Combine (ToolPath, ToolExe);
108 return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
111 public string AlgorithmId {
112 get { return (string) Bag ["AlgorithmId"]; }
113 set { Bag ["AlgorithmId"] = value; }
116 public string BaseAddress {
117 get { return (string) Bag ["BaseAddress"]; }
118 set { Bag ["BaseAddress"] = value; }
121 public string CompanyName {
122 get { return (string) Bag ["CompanyName"]; }
123 set { Bag ["CompanyName"] = value; }
126 public string Configuration {
127 get { return (string) Bag ["Configuration"]; }
128 set { Bag ["Configuration"] = value; }
131 public string Copyright {
132 get { return (string) Bag ["Copyright"]; }
133 set { Bag ["Copyright"] = value; }
136 public string Culture {
137 get { return (string) Bag ["Culture"]; }
138 set { Bag ["Culture"] = value; }
141 public bool DelaySign {
142 get { return GetBoolParameterWithDefault ("DelaySign", false); }
143 set { Bag ["DelaySign"] = value; }
146 public string Description {
147 get { return (string) Bag ["Description"]; }
148 set { Bag ["Description"] = value; }
151 public ITaskItem[] EmbedResources {
152 get { return (ITaskItem[]) Bag ["EmbedResources"]; }
153 set { Bag ["EmbedResources"] = value; }
156 public string EvidenceFile {
157 get { return (string) Bag ["EvidenceFile"]; }
158 set { Bag ["EvidenceFile"] = value; }
161 public string FileVersion {
162 get { return (string) Bag ["FileVersion"]; }
163 set { Bag ["FileVersion"] = value; }
166 public string Flags {
167 get { return (string) Bag ["Flags"]; }
168 set { Bag ["Flags"] = value; }
171 public bool GenerateFullPaths {
172 get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
173 set { Bag ["GenerateFullPaths"] = value; }
176 public string KeyContainer {
177 get { return (string) Bag ["KeyContainer"]; }
178 set { Bag ["KeyContainer"] = value; }
181 public string KeyFile {
182 get { return (string) Bag ["KeyFile"]; }
183 set { Bag ["KeyFile"] = value; }
186 public ITaskItem[] LinkResources {
187 get { return (ITaskItem[]) Bag ["LinkResources"]; }
188 set { Bag ["LinkResources"] = value; }
191 public string MainEntryPoint {
192 get { return (string) Bag ["MainEntryPoint"]; }
193 set { Bag ["MainEntryPoint"] = value; }
198 public ITaskItem OutputAssembly {
199 get { return (ITaskItem) Bag ["OutputAssembly"]; }
200 set { Bag ["OutputAssembly"] = value; }
203 public string Platform {
204 get { return (string) Bag ["Platform"]; }
205 set { Bag ["Platform"] = value; }
208 public string ProductName {
209 get { return (string) Bag ["ProductName"]; }
210 set { Bag ["ProductName"] = value; }
213 public string ProductVersion {
214 get { return (string) Bag ["ProductVersion"]; }
215 set { Bag ["ProductVersion"] = value; }
218 public string[] ResponseFiles {
219 get { return (string[]) Bag ["ResponseFiles"]; }
220 set { Bag ["ResponseFiles"] = value; }
223 public ITaskItem[] SourceModules {
224 get { return (ITaskItem[]) Bag ["SourceModules"]; }
225 set { Bag ["SourceModules"] = value; }
228 public string TargetType {
229 get { return (string) Bag ["TargetType"]; }
230 set { Bag ["TargetType"] = value; }
233 public string TemplateFile {
234 get { return (string) Bag ["TemplateFile"]; }
235 set { Bag ["TemplateFile"] = value; }
238 public string Title {
239 get { return (string) Bag ["Title"]; }
240 set { Bag ["Title"] = value; }
243 protected override string ToolName {
244 get { return "al.exe"; }
247 public string Trademark {
248 get { return (string) Bag ["Trademark"]; }
249 set { Bag ["Trademark"] = value; }
252 public string Version {
253 get { return (string) Bag ["Version"]; }
254 set { Bag ["Version"] = value; }
257 public string Win32Icon {
258 get { return (string) Bag ["Win32Icon"]; }
259 set { Bag ["Win32Icon"] = value; }
262 public string Win32Resource {
263 get { return (string) Bag ["Win32Resource"]; }
264 set { Bag ["Win32Resource"] = value; }