protected override HostObjectInitializationStatus InitializeHostObject() { if (base.HostObject != null) { using (RCWForCurrentContext <ICscHostObject> context = new RCWForCurrentContext <ICscHostObject>(base.HostObject as ICscHostObject)) { ICscHostObject rCW = context.RCW; if (rCW != null) { bool flag = this.InitializeHostCompiler(rCW); if (rCW.IsDesignTime()) { return(flag ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.NoActionReturnFailure); } if (!base.HostCompilerSupportsAllParameters || this.UseAlternateCommandLineToolToExecute()) { if (!base.CheckAllReferencesExistOnDisk()) { return(HostObjectInitializationStatus.NoActionReturnFailure); } base.UsedCommandLineTool = true; return(HostObjectInitializationStatus.UseAlternateToolToExecute); } if (flag) { return(rCW.IsUpToDate() ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.UseHostObjectToExecute); } return(HostObjectInitializationStatus.NoActionReturnFailure); } base.Log.LogErrorWithCodeFromResources("General.IncorrectHostObject", new object[] { "Csc", "ICscHostObject" }); } } base.UsedCommandLineTool = true; return(HostObjectInitializationStatus.UseAlternateToolToExecute); }
protected override HostObjectInitializationStatus InitializeHostObject() { if (HostObject != null) { // When the host object was passed into the task, it was passed in as a generic // "Object" (because ITask interface obviously can't have any Csc-specific stuff // in it, and each task is going to want to communicate with its host in a unique // way). Now we cast it to the specific type that the Csc task expects. If the // host object does not match this type, the host passed in an invalid host object // to Csc, and we error out. // NOTE: For compat reasons this must remain ICscHostObject // we can dynamically test for smarter interfaces later.. if (HostObject is ICscHostObject hostObjectCOM) { using (RCWForCurrentContext <ICscHostObject> hostObject = new RCWForCurrentContext <ICscHostObject>(hostObjectCOM)) { ICscHostObject cscHostObject = hostObject.RCW; bool hostObjectSuccessfullyInitialized = InitializeHostCompiler(cscHostObject); // If we're currently only in design-time (as opposed to build-time), // then we're done. We've initialized the host compiler as best we // can, and we certainly don't want to actually do the final compile. // So return true, saying we're done and successful. if (cscHostObject.IsDesignTime()) { // If we are design-time then we do not want to continue the build at // this time. return(hostObjectSuccessfullyInitialized ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.NoActionReturnFailure); } if (!this.HostCompilerSupportsAllParameters) { // Since the host compiler has refused to take on the responsibility for this compilation, // we're about to shell out to the command-line compiler to handle it. If some of the // references don't exist on disk, we know the command-line compiler will fail, so save // the trouble, and just throw a consistent error ourselves. This allows us to give // more information than the compiler would, and also make things consistent across // Vbc / Csc / etc. Actually, the real reason is bug 275726 (ddsuites\src\vs\env\vsproject\refs\ptp3). // This suite behaves differently in localized builds than on English builds because // VBC.EXE doesn't localize the word "error" when they emit errors and so we can't scan for it. if (!CheckAllReferencesExistOnDisk()) { return(HostObjectInitializationStatus.NoActionReturnFailure); } // The host compiler doesn't support some of the switches/parameters // being passed to it. Therefore, we resort to using the command-line compiler // in this case. UsedCommandLineTool = true; return(HostObjectInitializationStatus.UseAlternateToolToExecute); } // Ok, by now we validated that the host object supports the necessary switches // and parameters. Last thing to check is whether the host object is up to date, // and in that case, we will inform the caller that no further action is necessary. if (hostObjectSuccessfullyInitialized) { return(cscHostObject.IsUpToDate() ? HostObjectInitializationStatus.NoActionReturnSuccess : HostObjectInitializationStatus.UseHostObjectToExecute); } else { return(HostObjectInitializationStatus.NoActionReturnFailure); } } } else { Log.LogErrorWithCodeFromResources("General_IncorrectHostObject", "Csc", "ICscHostObject"); } } // No appropriate host object was found. UsedCommandLineTool = true; return(HostObjectInitializationStatus.UseAlternateToolToExecute); }