Merge pull request #1068 from esdrubal/bug18421
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / AL.cs
1 //
2 // AL.cs: Task for assembly linker
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2005 Marek Sieradzki
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
27
28 #if NET_2_0
29
30 using System;
31 using System.Diagnostics;
32 using System.IO;
33 using Microsoft.Build.Framework;
34 using Microsoft.Build.Utilities;
35 using Mono.XBuild.Utilities;
36
37 namespace Microsoft.Build.Tasks {
38         public class AL : ToolTaskExtension {
39         
40                 public AL ()
41                 {
42                 }
43                 
44                 [MonoTODO]
45                 protected internal override void AddResponseFileCommands (
46                                                  CommandLineBuilderExtension commandLine)
47                 {
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)
55                                 if (DelaySign)
56                                         commandLine.AppendSwitch ("/delaysign+");
57                                 else
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));
65                                         else
66                                                 commandLine.AppendSwitchIfNotNull ("/embed:", item.ItemSpec);
67                                 }
68                         }
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);
82                         //platform
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);
98                 }
99                 
100                 public override bool Execute ()
101                 {
102                         return base.Execute ();
103                 }
104
105                 protected override string GenerateFullPathToTool ()
106                 {
107                         if (!string.IsNullOrEmpty (ToolPath))
108                                 return Path.Combine (ToolPath, ToolExe);
109                         return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
110                 }
111
112                 public string AlgorithmId {
113                         get { return (string) Bag ["AlgorithmId"]; }
114                         set { Bag ["AlgorithmId"] = value; }
115                 }
116
117                 public string BaseAddress {
118                         get { return (string) Bag ["BaseAddress"]; }
119                         set { Bag ["BaseAddress"] = value; }
120                 }
121
122                 public string CompanyName {
123                         get { return (string) Bag ["CompanyName"]; }
124                         set { Bag ["CompanyName"] = value; }
125                 }
126
127                 public string Configuration {
128                         get { return (string) Bag ["Configuration"]; }
129                         set { Bag ["Configuration"] = value; }
130                 }
131
132                 public string Copyright {
133                         get { return (string) Bag ["Copyright"]; }
134                         set { Bag ["Copyright"] = value; }
135                 }
136
137                 public string Culture {
138                         get { return (string) Bag ["Culture"]; }
139                         set { Bag ["Culture"] = value; }
140                 }
141
142                 public bool DelaySign {
143                         get { return GetBoolParameterWithDefault ("DelaySign", false); }
144                         set { Bag ["DelaySign"] = value; }
145                 }
146
147                 public string Description {
148                         get { return (string) Bag ["Description"]; }
149                         set { Bag ["Description"] = value; }
150                 }
151
152                 public ITaskItem[] EmbedResources {
153                         get { return (ITaskItem[]) Bag ["EmbedResources"]; }
154                         set { Bag ["EmbedResources"] = value; }
155                 }
156
157                 public string EvidenceFile {
158                         get { return (string) Bag ["EvidenceFile"]; }
159                         set { Bag ["EvidenceFile"] = value; }
160                 }
161
162                 public string FileVersion {
163                         get { return (string) Bag ["FileVersion"]; }
164                         set { Bag ["FileVersion"] = value; }
165                 }
166
167                 public string Flags {
168                         get { return (string) Bag ["Flags"]; }
169                         set { Bag ["Flags"] = value; }
170                 }
171
172                 public bool GenerateFullPaths {
173                         get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
174                         set { Bag ["GenerateFullPaths"] = value; }
175                 }
176
177                 public string KeyContainer {
178                         get { return (string) Bag ["KeyContainer"]; }
179                         set { Bag ["KeyContainer"] = value; }
180                 }
181
182                 public string KeyFile {
183                         get { return (string) Bag ["KeyFile"]; }
184                         set { Bag ["KeyFile"] = value; }
185                 }
186
187                 public ITaskItem[] LinkResources {
188                         get { return (ITaskItem[]) Bag ["LinkResources"]; }
189                         set { Bag ["LinkResources"] = value; }
190                 }
191
192                 public string MainEntryPoint {
193                         get { return (string) Bag ["MainEntryPoint"]; }
194                         set { Bag ["MainEntryPoint"] = value; }
195                 }
196
197                 [Required]
198                 [Output]
199                 public ITaskItem OutputAssembly {
200                         get { return (ITaskItem) Bag ["OutputAssembly"]; }
201                         set { Bag ["OutputAssembly"] = value; }
202                 }
203
204                 public string Platform {
205                         get { return (string) Bag ["Platform"]; }
206                         set { Bag ["Platform"] = value; }
207                 }
208
209                 public string ProductName {
210                         get { return (string) Bag ["ProductName"]; }
211                         set { Bag ["ProductName"] = value; }
212                 }
213
214                 public string ProductVersion {
215                         get { return (string) Bag ["ProductVersion"]; }
216                         set { Bag ["ProductVersion"] = value; }
217                 }
218
219                 public string[] ResponseFiles {
220                         get { return (string[]) Bag ["ResponseFiles"]; }
221                         set { Bag ["ResponseFiles"] = value; }
222                 }
223
224                 public ITaskItem[] SourceModules {
225                         get { return (ITaskItem[]) Bag ["SourceModules"]; }
226                         set { Bag ["SourceModules"] = value; }
227                 }
228
229                 public string TargetType {
230                         get { return (string) Bag ["TargetType"]; }
231                         set { Bag ["TargetType"] = value; }
232                 }
233
234                 public string TemplateFile {
235                         get { return (string) Bag ["TemplateFile"]; }
236                         set { Bag ["TemplateFile"] = value; }
237                 }
238
239                 public string Title {
240                         get { return (string) Bag ["Title"]; }
241                         set { Bag ["Title"] = value; }
242                 }
243
244                 protected override string ToolName {
245                         get { return "al.exe"; }
246                 }
247
248                 public string Trademark {
249                         get { return (string) Bag ["Trademark"]; }
250                         set { Bag ["Trademark"] = value; }
251                 }
252
253                 public string Version {
254                         get { return (string) Bag ["Version"]; }
255                         set { Bag ["Version"] = value; }
256                 }
257
258                 public string Win32Icon {
259                         get { return (string) Bag ["Win32Icon"]; }
260                         set { Bag ["Win32Icon"] = value; }
261                 }
262
263                 public string Win32Resource {
264                         get { return (string) Bag ["Win32Resource"]; }
265                         set { Bag ["Win32Resource"] = value; }
266                 }
267         }
268 }
269
270 #endif