public bool Execute() { try { if ((!this.SupportExtensions) && ((this.ApplicationMarkup == null) || this.ApplicationMarkup.Count == 0)) { return(true); } else if (this.ApplicationMarkupWithTypeName == null || this.ApplicationMarkupWithTypeName.Count == 0) { return(true); } IList <Assembly> loadedAssemblyList = null; if (this.References != null) { loadedAssemblyList = XamlBuildTaskServices.Load(this.References, false); } Assembly localAssembly = null; if (LocalAssemblyReference != null) { try { localAssembly = XamlBuildTaskServices.Load(LocalAssemblyReference); loadedAssemblyList.Add(localAssembly); } catch (FileNotFoundException e) { XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, e.FileName, 0, 0); return(false); } } AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(XamlBuildTaskServices.ReflectionOnlyAssemblyResolve); XamlNsReplacingContext wxsc = new XamlNsReplacingContext(loadedAssemblyList, localAssembly.GetName().Name, this.AssemblyName); bool foundValidationErrors = false; if (!this.SupportExtensions) { foreach (string app in ApplicationMarkup) { try { if (!ProcessMarkupItem(app, wxsc, localAssembly)) { foundValidationErrors = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, app, 0, 0); return(false); } } } else { foreach (ITaskItem app in this.ApplicationMarkupWithTypeName.Values) { string inputMarkupFile = app.ItemSpec; try { if (!ProcessMarkupItem(inputMarkupFile, wxsc, localAssembly)) { foundValidationErrors = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, inputMarkupFile, 0, 0); return(false); } } if (!foundValidationErrors) { foundValidationErrors = !ExecuteExtensions(); if (!foundValidationErrors) { foundValidationErrors = this.BuildLogger.HasLoggedErrors; } } } return(!foundValidationErrors); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } // Log unknown errors that do not originate from the task. // Assumes that all known errors are logged when the exception is thrown. XamlBuildTaskServices.LogException(this.BuildLogger, e.Message); return(false); } }
public bool Execute() { try { if (this.ApplicationMarkup == null || this.ApplicationMarkup.Count == 0) { return(true); } if (!CodeDomProvider.IsDefinedLanguage(this.Language)) { throw FxTrace.Exception.Argument("Language", SR.UnrecognizedLanguage(this.Language)); } if (this.SupportExtensions) { this.xamlBuildTypeGenerationExtensions = XamlBuildTaskServices.GetXamlBuildTaskExtensions <IXamlBuildTypeGenerationExtension>( this.XamlBuildTaskTypeGenerationExtensionNames, this.BuildLogger, this.MSBuildProjectDirectory); } AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(XamlBuildTaskServices.ReflectionOnlyAssemblyResolve); bool retVal = true; // We load the assemblies for the real builds // For intellisense builds, we load them the first time only if (!IsInProcessXamlMarkupCompile || this.LoadedAssemblyList == null) { if (this.References != null) { try { this.LoadedAssemblyList = XamlBuildTaskServices.Load(this.References, IsInProcessXamlMarkupCompile); } catch (FileNotFoundException e) { XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, e.FileName, 0, 0); retVal = false; } } } CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider(this.Language); ProcessHelperClassGeneration(codeDomProvider); foreach (ITaskItem app in ApplicationMarkup) { string inputMarkupFile = app.ItemSpec; try { retVal &= ProcessMarkupItem(app, codeDomProvider); } catch (LoggableException e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, e.Source, e.LineNumber, e.LinePosition); retVal = false; } catch (FileLoadException e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, SR.AssemblyCannotBeResolved(XamlBuildTaskServices.FileNotLoaded), inputMarkupFile, 0, 0); retVal = false; } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, inputMarkupFile, 0, 0); retVal = false; } } // Add the files generated from extensions if (this.SupportExtensions) { if (retVal) { foreach (string fileName in this.BuildContextForExtensions.GeneratedFiles) { this.GeneratedCodeFiles.Add(fileName); } foreach (string fileName in this.BuildContextForExtensions.GeneratedResourceFiles) { this.GeneratedResources.Add(fileName); } } } return(retVal); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } // Log unknown errors that do not originate from the task. // Assumes that all known errors are logged when the exception is thrown. if (!(e is LoggableException)) { XamlBuildTaskServices.LogException(this.BuildLogger, e.Message); } return(false); } }