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 {
47 protected internal override void AddResponseFileCommands (
48 CommandLineBuilderExtension commandLine)
50 commandLine.AppendSwitchIfNotNull ("/algid:", AlgorithmId);
51 commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
52 commandLine.AppendSwitchIfNotNull ("/company:", CompanyName);
53 commandLine.AppendSwitchIfNotNull ("/configuration:", Configuration);
54 commandLine.AppendSwitchIfNotNull ("/copyright:", Copyright);
55 commandLine.AppendSwitchIfNotNull ("/culture:", Culture);
56 if (DelaySign == true)
57 commandLine.AppendSwitch ("/delaysign");
58 if (EmbedResources != null)
59 foreach (ITaskItem item in EmbedResources)
60 commandLine.AppendSwitchIfNotNull ("/embedresource:", item.ItemSpec);
61 commandLine.AppendSwitchIfNotNull ("/evidence:", EvidenceFile);
62 commandLine.AppendSwitchIfNotNull ("/fileversion:", FileVersion);
63 commandLine.AppendSwitchIfNotNull ("/flags:", Flags);
64 if (GenerateFullPaths == true)
65 commandLine.AppendSwitch ("/fullpaths");
66 commandLine.AppendSwitchIfNotNull ("/keyname:", KeyContainer);
67 commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
68 if (LinkResources != null)
69 foreach (ITaskItem item in LinkResources)
70 commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
71 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
72 if (OutputAssembly != null)
73 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
75 commandLine.AppendSwitchIfNotNull ("/product:", ProductName);
76 commandLine.AppendSwitchIfNotNull ("/productversion:", ProductVersion);
77 if (ResponseFiles != null)
78 foreach (string s in ResponseFiles)
79 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", s));
80 if (SourceModules != null)
81 foreach (ITaskItem item in SourceModules)
82 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
83 commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
84 commandLine.AppendSwitchIfNotNull ("/template:", TemplateFile);
85 commandLine.AppendSwitchIfNotNull ("/title:", Title);
86 commandLine.AppendSwitchIfNotNull ("/trademark:", Trademark);
87 commandLine.AppendSwitchIfNotNull ("/version:", Version);
88 commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
89 commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
92 public override bool Execute ()
94 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
95 AddResponseFileCommands (clbe);
97 alProcess = new Process ();
98 alProcess.StartInfo.Arguments = clbe.ToString ();
99 alProcess.StartInfo.FileName = GenerateFullPathToTool ();
101 alProcess.WaitForExit ();
105 protected override string GenerateFullPathToTool ()
107 return Path.Combine (ToolPath, ToolName);
110 public string AlgorithmId {
111 get { return (string) Bag ["AlgorithmId"]; }
112 set { Bag ["AlgorithmId"] = value; }
115 public string BaseAddress {
116 get { return (string) Bag ["BaseAddress"]; }
117 set { Bag ["BaseAddress"] = value; }
120 public string CompanyName {
121 get { return (string) Bag ["CompanyName"]; }
122 set { Bag ["CompanyName"] = value; }
125 public string Configuration {
126 get { return (string) Bag ["Configuration"]; }
127 set { Bag ["Configuration"] = value; }
130 public string Copyright {
131 get { return (string) Bag ["Copyright"]; }
132 set { Bag ["Copyright"] = value; }
135 public string Culture {
136 get { return (string) Bag ["Culture"]; }
137 set { Bag ["Culture"] = value; }
140 public bool DelaySign {
141 get { return GetBoolParameterWithDefault ("DelaySign", false); }
142 set { Bag ["DelaySign"] = value; }
145 public string Description {
146 get { return (string) Bag ["Description"]; }
147 set { Bag ["Description"] = value; }
150 public ITaskItem[] EmbedResources {
151 get { return (ITaskItem[]) Bag ["EmbedResources"]; }
152 set { Bag ["EmbedResources"] = value; }
155 public string EvidenceFile {
156 get { return (string) Bag ["EvidenceFile"]; }
157 set { Bag ["EvidenceFile"] = value; }
160 public string FileVersion {
161 get { return (string) Bag ["FileVersion"]; }
162 set { Bag ["FileVersion"] = value; }
165 public string Flags {
166 get { return (string) Bag ["Flags"]; }
167 set { Bag ["Flags"] = value; }
170 public bool GenerateFullPaths {
171 get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
172 set { Bag ["GenerateFullPaths"] = value; }
175 public string KeyContainer {
176 get { return (string) Bag ["KeyContainer"]; }
177 set { Bag ["KeyContainer"] = value; }
180 public string KeyFile {
181 get { return (string) Bag ["KeyFile"]; }
182 set { Bag ["KeyFile"] = value; }
185 public ITaskItem[] LinkResources {
186 get { return (ITaskItem[]) Bag ["LinkResources"]; }
187 set { Bag ["LinkResources"] = value; }
190 public string MainEntryPoint {
191 get { return (string) Bag ["MainEntryPoint"]; }
192 set { Bag ["MainEntryPoint"] = value; }
197 public ITaskItem OutputAssembly {
198 get { return (ITaskItem) Bag ["OutputAssembly"]; }
199 set { Bag ["OutputAssembly"] = value; }
202 public string Platform {
203 get { return (string) Bag ["Platform"]; }
204 set { Bag ["Platform"] = value; }
207 public string ProductName {
208 get { return (string) Bag ["ProductName"]; }
209 set { Bag ["ProductName"] = value; }
212 public string ProductVersion {
213 get { return (string) Bag ["ProductVersion"]; }
214 set { Bag ["ProductVersion"] = value; }
217 public string[] ResponseFiles {
218 get { return (string[]) Bag ["ResponseFiles"]; }
219 set { Bag ["ResponseFiles"] = value; }
222 public ITaskItem[] SourceModules {
223 get { return (ITaskItem[]) Bag ["SourceModules"]; }
224 set { Bag ["SourceModules"] = value; }
227 public string TargetType {
228 get { return (string) Bag ["TargetType"]; }
229 set { Bag ["TargetType"] = value; }
232 public string TemplateFile {
233 get { return (string) Bag ["TemplateFile"]; }
234 set { Bag ["TemplateFile"] = value; }
237 public string Title {
238 get { return (string) Bag ["Title"]; }
239 set { Bag ["Title"] = value; }
242 protected override string ToolName {
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; }