/// <summary> /// From an Assembly get the error/warning description. /// </summary> /// <param name="node"></param> /// <returns>Assembly resource found result</returns> private bool GetErrorWarningInfoFromAssemblyResources(XmlNode node) { if (node == null) { return(false); } XmlNode childnode = node.SelectSingleNode("./" + Constants.AssemblyResourceAssembly); if (childnode == null) { return(false); } AssemblySW assm = null; if (listofassembliesloaded == null) { listofassembliesloaded = new Hashtable(); } if (String.IsNullOrEmpty(childnode.InnerText)) { return(false); } string assemblyname = childnode.InnerText; if (assemblyname.Contains("Presentation")) { if (String.IsNullOrEmpty(presentationassemblyfullname)) { presentationassemblyfullname = MSBuildEngineCommonHelper.PresentationFrameworkFullName; } int startindex = presentationassemblyfullname.IndexOf(","); presentationassemblyfullname = presentationassemblyfullname.Substring(startindex); assemblyname = assemblyname + presentationassemblyfullname; } else { if (assemblyname.EndsWith(".dll") == false) { assemblyname += ".dll"; } if (String.IsNullOrEmpty(urtpath)) { urtpath = PathSW.GetDirectoryName(typeof(object).Assembly.Location) + PathSW.DirectorySeparatorChar; } assemblyname = urtpath + assemblyname; } childnode = node.SelectSingleNode("./" + Constants.AssemblyResoruceResourceName); if (childnode == null) { return(false); } if (String.IsNullOrEmpty(childnode.InnerText)) { return(false); } string resourcename = childnode.InnerText; if (listofresourcesloaded == null) { listofresourcesloaded = new Hashtable(); } childnode = node.SelectSingleNode("./" + Constants.AssemblyResourceErrorIdentifier); if (childnode == null) { return(false); } if (String.IsNullOrEmpty(childnode.InnerText)) { return(false); } string erroridentifier = childnode.InnerText; ResourceSetSW rs = null; string cultureinfo = null; if (listofresourcesloaded.Contains(resourcename) == false) { if (listofassembliesloaded.Contains(assemblyname)) { assm = (AssemblySW)listofassembliesloaded[assemblyname]; } else { if (FileSW.Exists(assemblyname)) { if (listofassembliesloaded.Contains(assemblyname) == false) { assm = AssemblySW.ReflectionOnlyLoadFrom(assemblyname); } else { assm = (AssemblySW)listofassembliesloaded[assemblyname]; } } else { //assm = Assembly.GetAssembly(typeof(Microsoft.Build.BuildEngine.BuildItem)); AssemblySW[] assmlist = AppDomainSW.CurrentDomain.GetAssemblies(); for (int i = 0; i < assmlist.Length; i++) { object obj = assmlist.GetValue(i); assm = (AssemblySW)obj; if (PathSW.GetFileNameWithoutExtension(assm.ManifestModule.Name).ToLowerInvariant() == assemblyname.ToLowerInvariant()) { break; } assm = null; obj = null; } assmlist = null; } } if (assm == null) { assm = AssemblySW.ReflectionOnlyLoad(assemblyname); if (assm == null) { throw new ApplicationException(assemblyname + " could not be loaded."); } } AssemblySW assm2 = null; try { assm2 = assm.GetSatelliteAssembly(System.Globalization.CultureInfo.CurrentUICulture); cultureinfo = System.Globalization.CultureInfo.CurrentUICulture.Name; assm = null; assm = assm2; assm2 = null; } catch (FileNotFoundException) { MSBuildEngineCommonHelper.LogDiagnostic = "Current UI culture = " + CultureInfo.CurrentUICulture.Name + " with full culture name"; MSBuildEngineCommonHelper.LogDiagnostic = "Assembly " + assm.FullName + " doesn't have a culture dependent resource assembly."; } try { assm2 = assm.GetSatelliteAssembly(System.Globalization.CultureInfo.CurrentUICulture.Parent); cultureinfo = System.Globalization.CultureInfo.CurrentUICulture.Parent.Name; assm = null; assm = assm2; assm2 = null; } catch (FileNotFoundException) { MSBuildEngineCommonHelper.LogDiagnostic = "Current UI culture = " + CultureInfo.CurrentUICulture.Parent.Name + " with full culture name"; MSBuildEngineCommonHelper.LogDiagnostic = "Assembly " + assm.FullName + " doesn't have a culture dependent resource assembly."; } string resourcenamewithculture = null; if (String.IsNullOrEmpty(cultureinfo) == false) { if (resourcename.Contains(".")) { string[] resourcesplit = resourcename.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (resourcesplit.Length >= 2) { if (resourcesplit[resourcesplit.Length - 1].ToLowerInvariant() == "resources") { int resindex = resourcename.IndexOf(".resources"); if (resindex > 0) { resourcenamewithculture = resourcename.Substring(0, resindex) + "." + cultureinfo + "." + resourcesplit[resourcesplit.Length - 1]; } } } resourcesplit = null; } } if (listofassembliesloaded.Contains(assemblyname) == false) { listofassembliesloaded.Add(assemblyname, assm); } string[] resourcenames = assm.GetManifestResourceNames(); bool resourcefound = false; for (int j = 0; j < resourcenames.Length; j++) { if (resourcename == resourcenames[j]) { resourcefound = true; break; } if (resourcenamewithculture == resourcenames[j]) { resourcefound = true; break; } } resourcenames = null; if (resourcefound) { StreamSW resourcestream = null; if (String.IsNullOrEmpty(cultureinfo)) { resourcestream = assm.GetManifestResourceStream(resourcename); rs = new ResourceSetSW(resourcestream.InnerObject); if (listofresourcesloaded.Contains(resourcename) == false) { listofresourcesloaded.Add(resourcename, rs); } resourcestream.Close(); } else { resourcestream = assm.GetManifestResourceStream(resourcenamewithculture); rs = new ResourceSetSW(resourcestream.InnerObject); if (listofresourcesloaded.Contains(resourcename) == false) { listofresourcesloaded.Add(resourcename, rs); } resourcestream.Close(); } resourcestream = null; } } else { rs = (ResourceSetSW)listofresourcesloaded[resourcename]; } if (rs != null) { string errordescription = rs.GetString(erroridentifier); if (String.IsNullOrEmpty(errordescription)) { return(false); } if (errordescription.StartsWith(id)) { try { Convert.ToInt16(id); } catch (FormatException) { errordescription = errordescription.Substring(id.Length); } //errordescription = errordescription.Substring(id.Length); startingmessage = errortype.ToString().ToLowerInvariant() + " " + id; errordescription = errordescription.Trim(); } if (errordescription.StartsWith(":")) { errordescription = errordescription.Substring(1).Trim(); } ConvertResourceDescriptionToArray(errordescription); errordescription = null; } else { MSBuildEngineCommonHelper.Log = "The following erroridentifier could not be found as resourceset was null."; MSBuildEngineCommonHelper.Log = "ErrorIdentifier = " + erroridentifier; MSBuildEngineCommonHelper.Log = "Resourcname = " + resourcename; MSBuildEngineCommonHelper.Log = "Culture = " + cultureinfo; MSBuildEngineCommonHelper.Log = "AssemblyName = " + assemblyname; } return(true); }
static Compiler() { msbuildDirectory = PathSW.GetDirectoryName(AssemblySW.Wrap(typeof(object).Assembly).Location); }