2 // Csc.cs: Task that runs C# compiler
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.
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Tasks.Hosting;
34 using Microsoft.Build.Utilities;
35 using Mono.XBuild.Utilities;
37 namespace Microsoft.Build.Tasks {
38 public class Csc : ManagedCompiler {
44 protected internal override void AddResponseFileCommands (CommandLineBuilderExtension commandLine)
46 base.AddResponseFileCommands (commandLine);
48 if (AdditionalLibPaths != null && AdditionalLibPaths.Length > 0)
49 commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
51 if (Bag ["AllowUnsafeBlocks"] != null)
52 if (AllowUnsafeBlocks)
53 commandLine.AppendSwitch ("/unsafe+");
55 commandLine.AppendSwitch ("/unsafe-");
59 if (Bag ["CheckForOverflowUnderflow"] != null)
60 if (CheckForOverflowUnderflow)
61 commandLine.AppendSwitch ("/checked+");
63 commandLine.AppendSwitch ("/checked-");
65 if (!String.IsNullOrEmpty (DefineConstants)) {
66 string [] defines = DefineConstants.Split (new char [] {';', ' '},
67 StringSplitOptions.RemoveEmptyEntries);
68 if (defines.Length > 0)
69 commandLine.AppendSwitchIfNotNull ("/define:",
70 String.Join (";", defines));
73 commandLine.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings);
75 commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
79 if (GenerateFullPaths)
80 commandLine.AppendSwitch ("/fullpaths");
82 commandLine.AppendSwitchIfNotNull ("/langversion:", LangVersion);
84 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
89 commandLine.AppendSwitch ("/nostdlib");
92 commandLine.AppendSwitchIfNotNull ("/platform:", Platform);
94 if (References != null)
95 foreach (ITaskItem item in References) {
96 string aliases = item.GetMetadata ("Aliases") ?? String.Empty;
97 aliases = aliases.Trim ();
98 if (aliases.Length > 0)
99 commandLine.AppendSwitchIfNotNull ("/reference:" + aliases + "=", item.ItemSpec);
101 commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
104 if (ResponseFiles != null)
105 foreach (ITaskItem item in ResponseFiles)
106 commandLine.AppendSwitchIfNotNull ("@", item.ItemSpec);
108 if (Bag ["WarningLevel"] != null)
109 commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
111 commandLine.AppendSwitchIfNotNull ("/warnaserror+:", WarningsAsErrors);
113 commandLine.AppendSwitchIfNotNull ("/warnaserror-:", WarningsNotAsErrors);
115 if (Win32Resource != null)
116 commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
120 protected override bool CallHostObjectToExecute ()
122 throw new NotImplementedException ();
125 protected override string GenerateFullPathToTool ()
127 return Path.Combine (ToolPath, ToolExe);
131 protected override HostObjectInitializationStatus InitializeHostObject ()
133 return HostObjectInitializationStatus.NoActionReturnSuccess;
136 public bool AllowUnsafeBlocks {
137 get { return GetBoolParameterWithDefault ("AllowUnsafeBlocks", false); }
138 set { Bag ["AllowUnsafeBlocks"] = value; }
141 public string BaseAddress {
142 get { return (string) Bag ["BaseAddress"]; }
143 set { Bag ["BaseAddress"] = value; }
146 public bool CheckForOverflowUnderflow {
147 get { return GetBoolParameterWithDefault ("CheckForOverflowUnderflow", false); }
148 set { Bag ["CheckForOverflowUnderflow"] = value; }
151 public string DisabledWarnings {
152 get { return (string) Bag ["DisabledWarnings"]; }
153 set { Bag ["DisabledWarnings"] = value; }
156 public string DocumentationFile {
157 get { return (string) Bag ["DocumentationFile"]; }
158 set { Bag ["DocumentationFile"] = value; }
161 public string ErrorReport {
162 get { return (string) Bag ["ErrorReport"]; }
163 set { Bag ["ErrorReport"] = value; }
166 public bool GenerateFullPaths {
167 get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
168 set { Bag ["GenerateFullPaths"] = value; }
171 public string LangVersion {
172 get { return (string) Bag ["LangVersion"]; }
173 set { Bag ["LangVersion"] = value; }
176 public string ModuleAssemblyName {
177 get { return (string) Bag ["ModuleAssemblyName"]; }
178 set { Bag ["ModuleAssemblyName"] = value; }
181 public bool NoStandardLib {
182 get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
183 set { Bag ["NoStandardLib"] = value; }
186 public string PdbFile {
187 get { return (string) Bag ["PdbFile"]; }
188 set { Bag ["PdbFile"] = value; }
191 public string Platform {
192 get { return (string) Bag ["Platform"]; }
193 set { Bag ["Platform"] = value; }
196 protected override string ToolName {
199 return MSBuildUtils.RunningOnWindows ? "dmcs.bat" : "dmcs";
201 return MSBuildUtils.RunningOnWindows ? "gmcs.bat" : "gmcs";
206 public bool UseHostCompilerIfAvailable {
207 get { return GetBoolParameterWithDefault ("UseHostCompilerIfAvailable", false); }
208 set { Bag ["UseHostCompilerIfAvailable"] = value; }
211 public int WarningLevel {
212 get { return GetIntParameterWithDefault ("WarningLevel", 4); }
213 set { Bag ["WarningLevel"] = value; }
216 public string WarningsAsErrors {
217 get { return (string) Bag ["WarningsAsErrors"]; }
218 set { Bag ["WarningsAsErrors"] = value; }
221 public string WarningsNotAsErrors {
222 get { return (string) Bag ["WarningsNotAsErrors"]; }
223 set { Bag ["WarningsNotAsErrors"] = value; }