2 // ManagedCompiler.cs: Task for compilers
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.
33 using Microsoft.Build.Framework;
35 namespace Microsoft.Build.Tasks {
36 public abstract class ManagedCompiler : ToolTaskExtension {
38 protected ManagedCompiler ()
42 protected internal override void AddCommandLineCommands (
43 CommandLineBuilderExtension commandLine)
47 protected internal override void AddResponseFileCommands (
48 CommandLineBuilderExtension commandLine)
50 commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
51 commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
52 //commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
54 commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
56 if (EmitDebugInformation)
57 commandLine.AppendSwitch ("/debug");
59 commandLine.AppendSwitchIfNotNull ("/keycontainer:", KeyContainer);
60 commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
61 // FIXME: add ids from metadata
62 if (LinkResources != null) {
63 foreach (ITaskItem item in LinkResources) {
64 commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
67 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
69 commandLine.AppendSwitch ("/noconfig");
71 commandLine.AppendSwitch ("/optimize");
72 if (OutputAssembly != null)
73 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
74 if (References != null) {
75 foreach (ITaskItem item in References) {
76 commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
79 if (Resources != null) {
80 foreach (ITaskItem item in Resources) {
81 commandLine.AppendSwitchIfNotNull ("/resource:", item.ItemSpec);
84 if (ResponseFiles != null) {
85 foreach (ITaskItem item in ResponseFiles) {
86 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}",item.ItemSpec));
89 if (Sources != null) {
90 foreach (ITaskItem item in Sources) {
91 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
94 commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
95 if (TreatWarningsAsErrors)
96 commandLine.AppendSwitch ("/warnaserror");
97 commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
98 commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
101 protected bool CheckAllReferencesExistOnDisk ()
103 foreach (ITaskItem item in (ITaskItem[])Bag ["References"])
104 if (File.Exists (item.GetMetadata ("FullPath")) == false)
109 protected void CheckHostObjectSupport (string parameterName,
110 bool resultFromHostObjectSetOperation)
114 protected override bool HandleTaskExecutionErrors (int exitCode,
115 bool taskLoggedErrors)
120 protected override bool ValidateParameters ()
125 public string[] AdditionalLibPaths {
126 get { return (string[]) Bag ["AdditionalLibPaths"]; }
127 set { Bag ["AdditionalLibPaths"] = value; }
130 public string[] AddModules {
131 get { return (string[]) Bag ["AddModules"]; }
132 set { Bag ["AddModules"] = value; }
135 public int CodePage {
136 get { return GetIntParameterWithDefault ("CodePage", 0); }
137 set { Bag ["CodePage"] = value; }
140 public string DebugType {
141 get { return (string) Bag ["DebugType"]; }
142 set { Bag ["DebugType"] = value; }
145 public string DefineConstants {
146 get { return (string) Bag ["DefineConstants"]; }
147 set { Bag ["DefineConstants"] = value; }
150 public bool DelaySign {
151 get { return GetBoolParameterWithDefault ("DelaySign", false); }
152 set { Bag ["DelaySign"] = value; }
155 public bool EmitDebugInformation {
156 get { return GetBoolParameterWithDefault ("EmitDebugInformation", false); }
157 set { Bag ["EmitDebugInformation"] = value; }
160 public int FileAlignment {
161 get { return GetIntParameterWithDefault ("FileAlignment", 0); }
162 set { Bag ["FileAlignment"] = value; }
165 protected bool HostCompilerSupportsAllParameters {
167 set { Bag ["HostCompilerSupportsAllParameters"] = value; }
170 public string KeyContainer {
171 get { return (string) Bag ["KeyContainer"]; }
172 set { Bag ["KeyContainer"] = value; }
175 public string KeyFile {
176 get { return (string) Bag ["KeyFile"]; }
177 set { Bag ["KeyFile"] = value; }
180 public ITaskItem[] LinkResources {
181 get { return (ITaskItem[]) Bag ["LinkResources"]; }
182 set { Bag ["LinkResources"] = value; }
185 public string MainEntryPoint {
186 get { return (string) Bag ["MainEntryPoint"]; }
187 set { Bag ["MainEntryPoint"] = value; }
190 public bool NoConfig {
191 get { return GetBoolParameterWithDefault ("NoConfig", false); }
192 set { Bag ["NoConfig"] = value; }
196 get { return GetBoolParameterWithDefault ("NoLogo", false); }
197 set { Bag ["NoLogo"] = value; }
200 public bool Optimize {
201 get { return GetBoolParameterWithDefault ("Optimize", false); }
202 set { Bag ["Optimize"] = value; }
205 public ITaskItem OutputAssembly {
206 get { return (ITaskItem) Bag ["OutputAssembly"]; }
207 set { Bag ["OutputAssembly"] = value; }
210 public ITaskItem[] References {
211 get { return (ITaskItem[]) Bag ["References"]; }
212 set { Bag ["References"] = value; }
215 public ITaskItem[] Resources {
216 get { return (ITaskItem[]) Bag ["Resources"]; }
217 set { Bag ["Resources"] = value; }
220 public ITaskItem[] ResponseFiles {
221 get { return (ITaskItem[]) Bag ["ResponseFiles"]; }
222 set { Bag ["ResponseFiles"] = value; }
225 public ITaskItem[] Sources {
226 get { return (ITaskItem[]) Bag ["Sources"]; }
227 set { Bag ["Sources"] = value; }
230 protected override Encoding StandardOutputEncoding {
231 get { return Console.Error.Encoding; }
234 public string TargetType {
235 get { return (string) Bag ["TargetType"]; }
236 set { Bag ["TargetType"] = value; }
239 public bool TreatWarningsAsErrors {
240 get { return GetBoolParameterWithDefault ("TreatWarningsAsErrors", false); }
241 set { Bag ["TreatWarningsAsErrors"] = value; }
244 public bool Utf8Output {
245 get { return GetBoolParameterWithDefault ("Utf8Output", false); }
246 set { Bag ["Utf8Output"] = value; }
249 public string Win32Icon {
250 get { return (string) Bag ["Win32Icon"]; }
251 set { Bag ["Win32Icon"] = value; }
254 public string Win32Resource {
255 get { return (string) Bag ["Win32Resource"]; }
256 set { Bag ["Win32Resource"] = value; }