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 if (AdditionalLibPaths
!= null && AdditionalLibPaths
.Length
> 0)
48 commandLine
.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths
, ",");
50 if (Bag
["AllowUnsafeBlocks"] != null)
51 if (AllowUnsafeBlocks
)
52 commandLine
.AppendSwitch ("/unsafe+");
54 commandLine
.AppendSwitch ("/unsafe-");
58 if (Bag
["CheckForOverflowUnderflow"] != null)
59 if (CheckForOverflowUnderflow
)
60 commandLine
.AppendSwitch ("/checked+");
62 commandLine
.AppendSwitch ("/checked-");
64 if (!String
.IsNullOrEmpty (DefineConstants
)) {
65 string [] defines
= DefineConstants
.Split (new char [] {';', ' '}
,
66 StringSplitOptions
.RemoveEmptyEntries
);
67 if (defines
.Length
> 0)
68 commandLine
.AppendSwitchUnquotedIfNotNull ("/define:",
69 String
.Join (";", defines
));
72 commandLine
.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings
);
74 commandLine
.AppendSwitchIfNotNull ("/doc:", DocumentationFile
);
78 if (GenerateFullPaths
)
79 commandLine
.AppendSwitch ("/fullpaths");
81 commandLine
.AppendSwitchIfNotNull ("/langversion:", LangVersion
);
83 commandLine
.AppendSwitchIfNotNull ("/main:", MainEntryPoint
);
88 commandLine
.AppendSwitch ("/nostdlib");
92 if (References
!= null)
93 foreach (ITaskItem item
in References
)
94 commandLine
.AppendSwitchIfNotNull ("/reference:", item
.ItemSpec
);
96 if (ResponseFiles
!= null)
97 foreach (ITaskItem item
in ResponseFiles
)
98 commandLine
.AppendSwitchIfNotNull ("@", item
.ItemSpec
);
100 if (Bag
["WarningLevel"] != null)
101 commandLine
.AppendSwitchIfNotNull ("/warn:", WarningLevel
.ToString ());
103 commandLine
.AppendSwitchIfNotNull ("/warnaserror+:", WarningsAsErrors
);
105 commandLine
.AppendSwitchIfNotNull ("/warnaserror-:", WarningsNotAsErrors
);
107 if (Win32Resource
!= null)
108 commandLine
.AppendSwitchIfNotNull ("/win32res:", Win32Resource
);
112 protected override bool CallHostObjectToExecute ()
114 throw new NotImplementedException ();
117 protected override string GenerateFullPathToTool ()
119 return Path
.Combine (ToolPath
, ToolExe
);
123 protected override HostObjectInitializationStatus
InitializeHostObject ()
125 return HostObjectInitializationStatus
.NoActionReturnSuccess
;
128 public bool AllowUnsafeBlocks
{
129 get { return GetBoolParameterWithDefault ("AllowUnsafeBlocks", false); }
130 set { Bag ["AllowUnsafeBlocks"] = value; }
133 public string BaseAddress
{
134 get { return (string) Bag ["BaseAddress"]; }
135 set { Bag ["BaseAddress"] = value; }
138 public bool CheckForOverflowUnderflow
{
139 get { return GetBoolParameterWithDefault ("CheckForOverflowUnderflow", false); }
140 set { Bag ["CheckForOverflowUnderflow"] = value; }
143 public string DisabledWarnings
{
144 get { return (string) Bag ["DisabledWarnings"]; }
145 set { Bag ["DisabledWarnings"] = value; }
148 public string DocumentationFile
{
149 get { return (string) Bag ["DocumentationFile"]; }
150 set { Bag ["DocumentationFile"] = value; }
153 public string ErrorReport
{
154 get { return (string) Bag ["ErrorReport"]; }
155 set { Bag ["ErrorReport"] = value; }
158 public bool GenerateFullPaths
{
159 get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
160 set { Bag ["GenerateFullPaths"] = value; }
163 public string LangVersion
{
164 get { return (string) Bag ["LangVersion"]; }
165 set { Bag ["LangVersion"] = value; }
168 public string ModuleAssemblyName
{
169 get { return (string) Bag ["ModuleAssemblyName"]; }
170 set { Bag ["ModuleAssemblyName"] = value; }
173 public bool NoStandardLib
{
174 get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
175 set { Bag ["NoStandardLib"] = value; }
178 public string PdbFile
{
179 get { return (string) Bag ["PdbFile"]; }
180 set { Bag ["PdbFile"] = value; }
183 public string Platform
{
184 get { return (string) Bag ["Platform"]; }
185 set { Bag ["Platform"] = value; }
188 protected override string ToolName
{
191 return Utilities
.RunningOnWindows
? "dmcs.bat" : "dmcs";
193 return Utilities
.RunningOnWindows
? "gmcs.bat" : "gmcs";
198 public bool UseHostCompilerIfAvailable
{
199 get { return GetBoolParameterWithDefault ("UseHostCompilerIfAvailable", false); }
200 set { Bag ["UseHostCompilerIfAvailable"] = value; }
203 public int WarningLevel
{
204 get { return GetIntParameterWithDefault ("WarningLevel", 4); }
205 set { Bag ["WarningLevel"] = value; }
208 public string WarningsAsErrors
{
209 get { return (string) Bag ["WarningsAsErrors"]; }
210 set { Bag ["WarningsAsErrors"] = value; }
213 public string WarningsNotAsErrors
{
214 get { return (string) Bag ["WarningsNotAsErrors"]; }
215 set { Bag ["WarningsNotAsErrors"] = value; }