/// <summary>Returns a host object initialization status value that indicates what the next action should be.</summary> /// <returns>A host object initialization status value that indicates what the next action should be.</returns> protected override HostObjectInitializationStatus InitializeHostObject() { if (base.HostObject != null) { using (RCWForCurrentContext <ICscHostObject> rCWForCurrentContext = new RCWForCurrentContext <ICscHostObject>(base.HostObject as ICscHostObject)) { ICscHostObject rCW = rCWForCurrentContext.RCW; if (rCW != null) { bool flag = this.InitializeHostCompiler(rCW); if (rCW.IsDesignTime()) { HostObjectInitializationStatus result = flag ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.NoActionReturnFailure; return(result); } if (!base.HostCompilerSupportsAllParameters || this.UseAlternateCommandLineToolToExecute()) { HostObjectInitializationStatus result; if (!base.CheckAllReferencesExistOnDisk()) { result = HostObjectInitializationStatus.NoActionReturnFailure; return(result); } base.UsedCommandLineTool = true; result = HostObjectInitializationStatus.UseAlternateToolToExecute; return(result); } else { HostObjectInitializationStatus result; if (flag) { result = (rCW.IsUpToDate() ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.UseHostObjectToExecute); return(result); } result = HostObjectInitializationStatus.NoActionReturnFailure; return(result); } } else { base.Log.LogErrorWithCodeFromResources("General.IncorrectHostObject", new object[] { "Csc", "ICscHostObject" }); } } } base.UsedCommandLineTool = true; return(HostObjectInitializationStatus.UseAlternateToolToExecute); }
public override bool Execute() { bool flag2; if (!this.ValidateParameters()) { return(false); } if (this.EnvironmentVariables != null) { this.environmentVariablePairs = new List <KeyValuePair <object, object> >(this.EnvironmentVariables.Length); foreach (string str in this.EnvironmentVariables) { string[] strArray = str.Split(equalsSplitter, 2); if ((strArray.Length == 1) || ((strArray.Length == 2) && (strArray[0].Length == 0))) { this.LogPrivate.LogErrorWithCodeFromResources("ToolTask.InvalidEnvironmentParameter", new object[] { strArray[0] }); return(false); } this.environmentVariablePairs.Add(new KeyValuePair <object, object>(strArray[0], strArray[1])); } } if (!this.AssignStandardStreamLoggingImportance()) { return(false); } try { if (this.SkipTaskExecution()) { return(true); } string contents = this.GenerateCommandLineCommands(); string message = contents; string responseFileCommands = this.GenerateResponseFileCommands(); if (this.UseCommandProcessor) { this.ToolExe = "cmd.exe"; this.temporaryBatchFile = FileUtilities.GetTemporaryFile(".cmd"); File.AppendAllText(this.temporaryBatchFile, contents, Encoding.ASCII); string temporaryBatchFile = this.temporaryBatchFile; if (temporaryBatchFile.Contains("&") && !temporaryBatchFile.Contains("^&")) { temporaryBatchFile = NativeMethodsShared.GetShortFilePath(temporaryBatchFile).Replace("&", "^&"); } contents = "/C \"" + temporaryBatchFile + "\""; if (this.EchoOff) { contents = "/Q " + contents; } } if ((contents == null) || (contents.Length == 0)) { contents = string.Empty; } else { contents = " " + contents; } HostObjectInitializationStatus status = this.InitializeHostObject(); switch (status) { case HostObjectInitializationStatus.NoActionReturnSuccess: return(true); case HostObjectInitializationStatus.NoActionReturnFailure: this.exitCode = 1; return(this.HandleTaskExecutionErrors()); default: { string pathToTool = this.ComputePathToTool(); if (pathToTool == null) { return(false); } bool alreadyLoggedEnvironmentHeader = false; StringDictionary environmentOverride = this.EnvironmentOverride; if (environmentOverride != null) { foreach (DictionaryEntry entry in environmentOverride) { alreadyLoggedEnvironmentHeader = this.LogEnvironmentVariable(alreadyLoggedEnvironmentHeader, (string)entry.Key, (string)entry.Value); } } if (this.environmentVariablePairs != null) { foreach (KeyValuePair <object, object> pair in this.environmentVariablePairs) { alreadyLoggedEnvironmentHeader = this.LogEnvironmentVariable(alreadyLoggedEnvironmentHeader, (string)pair.Key, (string)pair.Value); } } if (this.UseCommandProcessor) { this.LogToolCommand(pathToTool + contents); this.LogToolCommand(message); } else { this.LogToolCommand(pathToTool + contents + " " + responseFileCommands); } this.exitCode = 0; if (status == HostObjectInitializationStatus.UseHostObjectToExecute) { try { if (!this.CallHostObjectToExecute()) { this.exitCode = 1; } break; } catch (Exception exception) { this.LogPrivate.LogErrorFromException(exception); return(false); } } ErrorUtilities.VerifyThrow(status == HostObjectInitializationStatus.UseAlternateToolToExecute, "Invalid return status"); this.exitCode = this.ExecuteTool(pathToTool, responseFileCommands, contents); break; } } if (this.terminatedTool) { return(false); } if (this.exitCode != 0) { return(this.HandleTaskExecutionErrors()); } flag2 = true; } catch (ArgumentException exception2) { if (!this.terminatedTool) { this.LogPrivate.LogErrorWithCodeFromResources("General.InvalidToolSwitch", new object[] { this.ToolExe, this.GetErrorMessageWithDiagnosticsCheck(exception2) }); } flag2 = false; } catch (Win32Exception exception3) { if (!this.terminatedTool) { this.LogPrivate.LogErrorWithCodeFromResources("ToolTask.CouldNotStartToolExecutable", new object[] { this.ToolExe, this.GetErrorMessageWithDiagnosticsCheck(exception3) }); } flag2 = false; } catch (IOException exception4) { if (!this.terminatedTool) { this.LogPrivate.LogErrorWithCodeFromResources("ToolTask.CouldNotStartToolExecutable", new object[] { this.ToolExe, this.GetErrorMessageWithDiagnosticsCheck(exception4) }); } flag2 = false; } catch (UnauthorizedAccessException exception5) { if (!this.terminatedTool) { this.LogPrivate.LogErrorWithCodeFromResources("ToolTask.CouldNotStartToolExecutable", new object[] { this.ToolExe, this.GetErrorMessageWithDiagnosticsCheck(exception5) }); } flag2 = false; } finally { if ((this.temporaryBatchFile != null) && File.Exists(this.temporaryBatchFile)) { File.Delete(this.temporaryBatchFile); } } return(flag2); }