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;
36 namespace Microsoft.Build.Tasks {
37 public class Csc : ManagedCompiler {
43 protected internal override void AddResponseFileCommands (CommandLineBuilderExtension commandLine)
45 base.AddResponseFileCommands (commandLine);
47 commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
49 if (Bag ["AllowUnsafeBlocks"] != null)
50 if (AllowUnsafeBlocks)
51 commandLine.AppendSwitch ("/unsafe+");
53 commandLine.AppendSwitch ("/unsafe-");
57 if (Bag ["CheckForOverflowUnderflow"] != null)
58 if (CheckForOverflowUnderflow)
59 commandLine.AppendSwitch ("/checked+");
61 commandLine.AppendSwitch ("/checked-");
63 commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
65 commandLine.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings);
67 commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
71 if (GenerateFullPaths)
72 commandLine.AppendSwitch ("/fullpaths");
74 commandLine.AppendSwitchIfNotNull ("/langversion:", LangVersion);
76 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
81 commandLine.AppendSwitch ("/nostdlib");
85 if (References != null)
86 foreach (ITaskItem item in References)
87 commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
89 if (ResponseFiles != null)
90 foreach (ITaskItem item in ResponseFiles)
91 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}",item.ItemSpec));
93 if (Bag ["WarningLevel"] != null)
94 commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
96 commandLine.AppendSwitchIfNotNull ("/warnaserror+:", WarningsAsErrors);
98 commandLine.AppendSwitchIfNotNull ("/warnaserror-:", WarningsNotAsErrors);
100 if (Win32Resource != null)
101 commandLine.AppendSwitchIfNotNull ("/win32res:", String.Format ("\"{0}\"", Win32Resource));
105 protected override bool CallHostObjectToExecute ()
107 throw new NotImplementedException ();
110 protected override string GenerateFullPathToTool ()
112 return Path.Combine (ToolPath, ToolName);
116 protected override HostObjectInitializationStatus InitializeHostObject ()
118 return HostObjectInitializationStatus.NoActionReturnSuccess;
121 public bool AllowUnsafeBlocks {
122 get { return GetBoolParameterWithDefault ("AllowUnsafeBlocks", false); }
123 set { Bag ["AllowUnsafeBlocks"] = value; }
126 public string BaseAddress {
127 get { return (string) Bag ["BaseAddress"]; }
128 set { Bag ["BaseAddress"] = value; }
131 public bool CheckForOverflowUnderflow {
132 get { return GetBoolParameterWithDefault ("CheckForOverflowUnderflow", false); }
133 set { Bag ["CheckForOverflowUnderflow"] = value; }
136 public string DisabledWarnings {
137 get { return (string) Bag ["DisabledWarnings"]; }
138 set { Bag ["DisabledWarnings"] = value; }
141 public string DocumentationFile {
142 get { return (string) Bag ["DocumentationFile"]; }
143 set { Bag ["DocumentationFile"] = value; }
146 public string ErrorReport {
147 get { return (string) Bag ["ErrorReport"]; }
148 set { Bag ["ErrorReport"] = value; }
151 public bool GenerateFullPaths {
152 get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
153 set { Bag ["GenerateFullPaths"] = value; }
156 public string LangVersion {
157 get { return (string) Bag ["LangVersion"]; }
158 set { Bag ["LangVersion"] = value; }
161 public string ModuleAssemblyName {
162 get { return (string) Bag ["ModuleAssemblyName"]; }
163 set { Bag ["ModuleAssemblyName"] = value; }
166 public bool NoStandardLib {
167 get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
168 set { Bag ["NoStandardLib"] = value; }
171 public string PdbFile {
172 get { return (string) Bag ["PdbFile"]; }
173 set { Bag ["PdbFile"] = value; }
176 public string Platform {
177 get { return (string) Bag ["Platform"]; }
178 set { Bag ["Platform"] = value; }
181 protected override string ToolName {
182 get { return "gmcs"; }
185 public bool UseHostCompilerIfAvailable {
186 get { return GetBoolParameterWithDefault ("UseHostCompilerIfAvailable", false); }
187 set { Bag ["UseHostCompilerIfAvailable"] = value; }
190 public int WarningLevel {
191 get { return GetIntParameterWithDefault ("WarningLevel", 4); }
192 set { Bag ["WarningLevel"] = value; }
195 public string WarningsAsErrors {
196 get { return (string) Bag ["WarningsAsErrors"]; }
197 set { Bag ["WarningsAsErrors"] = value; }
200 public string WarningsNotAsErrors {
201 get { return (string) Bag ["WarningsNotAsErrors"]; }
202 set { Bag ["WarningsNotAsErrors"] = value; }