public bool Execute(XamlBuildTypeInspectionExtensionContext buildContext) { if (buildContext == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("buildContext")); } this.buildContext = buildContext; this.violations = new List <Violation>(); try { this.Execute(); // Delay validation report and always returns true in order to let CoreCompile to compile first. // CoreCompile will report expression compile errors and duplicated errors will be merged by Microsoft.VisualStudio.Activities.BuildHelper later. // ReportValidationBuildExtensionErrors will report validation errors after CoreCompile done. this.WriteViolationsToDeferredErrorsFile(); return(true); } catch (BadImageFormatException bex) { buildContext.XamlBuildLogger.LogWarning(SR.BadImageFormat_Validation(bex.FileName)); return(true); } }
public bool Execute(XamlBuildTypeInspectionExtensionContext buildContext) { if (buildContext == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("buildContext")); } this.buildContext = buildContext; string deferredValidationErrorsFilePath = Path.Combine(this.buildContext.OutputPath, ValidationBuildExtension.DeferredValidationErrorsFileName); if (string.Equals(this.buildContext.Language, "VB", StringComparison.OrdinalIgnoreCase) && File.Exists(deferredValidationErrorsFilePath)) { List <ValidationBuildExtension.Violation> violations = ReportDeferredValidationErrorsTask.LoadDeferredValidationErrors(deferredValidationErrorsFilePath); if (violations != null && violations.Count > 0) { // ValidationBuildExtension must have run prior to ExpressionBuildExtension. // If ValidationBuildExtension had cached any validation errors including VB Hosted compiler errors, // then we do not generate the compiled expression code for VB. return(true); } } this.generatedFiles = new List <string>(); this.messages = new List <Tuple <string, bool> >(); try { bool success = Execute(); foreach (string fileName in this.generatedFiles) { buildContext.AddGeneratedFile(fileName); } foreach (Tuple <string, bool> message in this.messages) { if (message.Item2) { buildContext.XamlBuildLogger.LogError(message.Item1); } else { buildContext.XamlBuildLogger.LogMessage(message.Item1); } } return(success); } catch (BadImageFormatException bex) { buildContext.XamlBuildLogger.LogWarning(SR.BadImageFormat_Expression(bex.FileName)); // We don't want to add the generated files to the project, since compilation was incomplete; // so we're responsible for cleaning them up ourselves. try { foreach (string fileName in this.generatedFiles) { File.Delete(fileName); } } catch (IOException) { // cleanup is best-effort } return(true); } }