Merge pull request #900 from Blewzman/FixAggregateExceptionGetBaseException
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / Csc.cs
index 2b334d88d811a4a3bcd1adf93cf78782a65455b8..142e73eddeb802dc009295d558a072bb7957652a 100644 (file)
@@ -32,6 +32,7 @@ using System.IO;
 using Microsoft.Build.Framework;
 using Microsoft.Build.Tasks.Hosting;
 using Microsoft.Build.Utilities;
+using Mono.XBuild.Utilities;
 
 namespace Microsoft.Build.Tasks {
        public class Csc : ManagedCompiler {
@@ -40,26 +41,88 @@ namespace Microsoft.Build.Tasks {
                {
                }
 
-               [MonoTODO]
                protected internal override void AddResponseFileCommands (CommandLineBuilderExtension commandLine)
                {
+#if !NET_4_0
+                       //pre-MSBuild 2 targets don't support multi-targeting, so tell compiler to use 2.0 corlib
+                       commandLine.AppendSwitch ("/sdk:2");
+#endif
                        base.AddResponseFileCommands (commandLine);
-                       
-                       if (AllowUnsafeBlocks == true)
-                               commandLine.AppendSwitch ("/unsafe");
+
+                       if (AdditionalLibPaths != null && AdditionalLibPaths.Length > 0)
+                               commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
+
+                       if (Bag ["AllowUnsafeBlocks"] != null)
+                               if (AllowUnsafeBlocks)
+                                       commandLine.AppendSwitch ("/unsafe+");
+                               else
+                                       commandLine.AppendSwitch ("/unsafe-");
+
                        //baseAddress
-                       //checkForOverflowUnderflow
-                       commandLine.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings);
+                       
+                       if (Bag ["CheckForOverflowUnderflow"] != null)
+                               if (CheckForOverflowUnderflow)
+                                       commandLine.AppendSwitch ("/checked+");
+                               else
+                                       commandLine.AppendSwitch ("/checked-");
+
+                       if (!String.IsNullOrEmpty (DefineConstants)) {
+                               string [] defines = DefineConstants.Split (new char [] {';', ' '},
+                                               StringSplitOptions.RemoveEmptyEntries);
+                               if (defines.Length > 0)
+                                       commandLine.AppendSwitchIfNotNull ("/define:",
+                                                       String.Join (";", defines));
+                       }
+
+                       if (!String.IsNullOrEmpty (DisabledWarnings)) {
+                               string [] defines = DisabledWarnings.Split (new char [] {';', ' ', ','},
+                                               StringSplitOptions.RemoveEmptyEntries);
+                               if (defines.Length > 0)
+                                   commandLine.AppendSwitchIfNotNull ("/nowarn:", defines, ";");
+                       }
+
                        commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
+
                        //errorReport
+
+                       if (GenerateFullPaths)
+                               commandLine.AppendSwitch ("/fullpaths");
+
                        commandLine.AppendSwitchIfNotNull ("/langversion:", LangVersion);
+
+                       commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
+
                        //moduleAssemblyName
+                       
                        if (NoStandardLib)
                                commandLine.AppendSwitch ("/nostdlib");
+
                        //platform
-                       commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
-                       //warningsAsErrors
-                       //warningNotAsErrors
+                       commandLine.AppendSwitchIfNotNull ("/platform:", Platform);
+                       //
+                       if (References != null)
+                               foreach (ITaskItem item in References) {
+                                       string aliases = item.GetMetadata ("Aliases") ?? String.Empty;
+                                       aliases = aliases.Trim ();
+                                       if (aliases.Length > 0)
+                                               commandLine.AppendSwitchIfNotNull ("/reference:" + aliases + "=", item.ItemSpec);
+                                       else
+                                               commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
+                               }
+
+                       if (ResponseFiles != null)
+                               foreach (ITaskItem item in ResponseFiles) 
+                                       commandLine.AppendSwitchIfNotNull ("@", item.ItemSpec);
+
+                       if (Bag ["WarningLevel"] != null)
+                               commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
+
+                       commandLine.AppendSwitchIfNotNull ("/warnaserror+:", WarningsAsErrors);
+
+                       commandLine.AppendSwitchIfNotNull ("/warnaserror-:", WarningsNotAsErrors);
+
+                       if (Win32Resource != null)
+                               commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
                }
 
                [MonoTODO]
@@ -70,7 +133,9 @@ namespace Microsoft.Build.Tasks {
 
                protected override string GenerateFullPathToTool ()
                {
-                       return Path.Combine (ToolPath, ToolName);
+                       if (!string.IsNullOrEmpty (ToolPath))
+                               return Path.Combine (ToolPath, ToolExe);
+                       return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
                }
 
                [MonoTODO]
@@ -140,7 +205,9 @@ namespace Microsoft.Build.Tasks {
                }
 
                protected override string ToolName {
-                       get { return "gmcs"; }
+                       get {
+                               return "mcs.exe";
+                       }
                }
 
                public bool UseHostCompilerIfAvailable {
@@ -149,7 +216,7 @@ namespace Microsoft.Build.Tasks {
                }
 
                public int WarningLevel {
-                       get { return GetIntParameterWithDefault ("WarningLevel", 2); }
+                       get { return GetIntParameterWithDefault ("WarningLevel", 4); }
                        set { Bag ["WarningLevel"] = value; }
                }