private static Manifest Deserialize(Stream s) { s.Position = 0; XmlTextReader r = new XmlTextReader(s); r.DtdProcessing = DtdProcessing.Ignore; do { r.Read(); }while (r.NodeType != XmlNodeType.Element); string ns = typeof(Util).Namespace; string tn = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", ns, r.Name); Type t = Type.GetType(tn); s.Position = 0; XmlSerializer xs = new XmlSerializer(t); int t1 = Environment.TickCount; XmlReaderSettings xrSettings = new XmlReaderSettings(); xrSettings.DtdProcessing = DtdProcessing.Ignore; using (XmlReader xr = XmlReader.Create(s, xrSettings)) { Manifest m = (Manifest)xs.Deserialize(xr); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestReader.Deserialize t={0}", Environment.TickCount - t1)); return(m); } }
public void WriteManifest(Stream input, Stream output) { int tickCount = Environment.TickCount; XmlDocument document = new XmlDocument(); document.Load(input); XmlNamespaceManager namespaceManager = XmlNamespaces.GetNamespaceManager(document.NameTable); XmlElement element = (XmlElement)document.SelectSingleNode("asmv1:assembly", namespaceManager); if (element == null) { throw new BadImageFormatException(); } XmlElement newChild = (XmlElement)element.SelectSingleNode("asmv2:trustInfo", namespaceManager); if (newChild == null) { newChild = document.CreateElement(XmlUtil.TrimPrefix("asmv2:trustInfo"), "urn:schemas-microsoft-com:asm.v2"); element.AppendChild(newChild); } if (((this._inputTrustInfoDocument != null) && (this._outputPermissionSet == null)) && !this.sameSiteChanged) { XmlElement element3 = (XmlElement)document.ImportNode(this._inputTrustInfoDocument.DocumentElement, true); newChild.ParentNode.ReplaceChild(element3, newChild); } else { XmlElement element4 = (XmlElement)newChild.SelectSingleNode("asmv2:security", namespaceManager); if (element4 == null) { element4 = document.CreateElement(XmlUtil.TrimPrefix("asmv2:security"), "urn:schemas-microsoft-com:asm.v2"); newChild.AppendChild(element4); } XmlElement element5 = (XmlElement)element4.SelectSingleNode("asmv2:applicationRequestMinimum", namespaceManager); if (element5 == null) { element5 = document.CreateElement(XmlUtil.TrimPrefix("asmv2:applicationRequestMinimum"), "urn:schemas-microsoft-com:asm.v2"); element4.AppendChild(element5); } foreach (XmlNode node in element5.SelectNodes("asmv2:PermissionSet", namespaceManager)) { element5.RemoveChild(node); } XmlDocument outputPermissionSetDocument = this.GetOutputPermissionSetDocument(); XmlElement element6 = (XmlElement)document.ImportNode(outputPermissionSetDocument.DocumentElement, true); element5.AppendChild(element6); this.FixupPermissionSetElement(element6); } if (output.Length > 0L) { output.SetLength(0L); output.Flush(); } document.Save(output); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteTrustInfo t={0}", new object[] { Environment.TickCount - tickCount })); }
private static Stream Serialize(Manifest manifest) { manifest.OnBeforeSave(); MemoryStream stream = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(manifest.GetType()); StreamWriter writer = new StreamWriter(stream); int tickCount = Environment.TickCount; serializer.Serialize((TextWriter)writer, manifest); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.Serialize t={0}", new object[] { Environment.TickCount - tickCount })); writer.Flush(); stream.Position = 0L; return(stream); }
/// <summary> /// Reads the specified manifest XML and returns an object representation. /// </summary> /// <param name="manifestType">Specifies the expected type of the manifest. Valid values are "AssemblyManifest", "ApplicationManifest", or "DepoyManifest".</param> /// <param name="input">Specifies an input stream.</param> /// <param name="preserveStream">Specifies whether to preserve the input stream in the InputStream property of the resulting manifest object. Used by ManifestWriter to reconstitute input which is not represented in the object representation.</param> /// <returns>A base object representation of the manifest. Can be cast to AssemblyManifest, ApplicationManifest, or DeployManifest to access more specific functionality.</returns> public static Manifest ReadManifest(string manifestType, Stream input, bool preserveStream) { int t1 = Environment.TickCount; const string resource = "read2.xsl"; Manifest m; Stream s; if (manifestType != null) { DictionaryEntry arg = new DictionaryEntry("manifest-type", manifestType); s = XmlUtil.XslTransform(resource, input, arg); } else { s = XmlUtil.XslTransform(resource, input); } try { s.Position = 0; m = Deserialize(s); if (m.GetType() == typeof(ApplicationManifest)) { var am = (ApplicationManifest)m; am.TrustInfo = new TrustInfo(); am.TrustInfo.ReadManifest(input); } if (preserveStream) { input.Position = 0; m.InputStream = new MemoryStream(); Util.CopyStream(input, m.InputStream); } s.Position = 0; string n = m.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All); if (String.IsNullOrEmpty(n)) { n = m.GetType().Name; } Util.WriteLogFile(n + ".read.xml", s); } finally { s.Close(); } Util.WriteLog(String.Format(CultureInfo.InvariantCulture, "ManifestReader.ReadManifest t={0}", Environment.TickCount - t1)); m.OnAfterLoad(); return(m); }
public static Manifest ReadManifest(string manifestType, Stream input, bool preserveStream) { Stream stream; int tickCount = Environment.TickCount; string resource = "read2.xsl"; Manifest manifest = null; if (manifestType != null) { DictionaryEntry entry = new DictionaryEntry("manifest-type", manifestType); DictionaryEntry[] entries = new DictionaryEntry[] { entry }; stream = XmlUtil.XslTransform(resource, input, entries); } else { stream = XmlUtil.XslTransform(resource, input, new DictionaryEntry[0]); } try { stream.Position = 0L; manifest = Deserialize(stream); if (manifest.GetType() == typeof(ApplicationManifest)) { ApplicationManifest manifest2 = (ApplicationManifest)manifest; manifest2.TrustInfo = new TrustInfo(); manifest2.TrustInfo.ReadManifest(input); } if (preserveStream) { input.Position = 0L; manifest.InputStream = new MemoryStream(); Util.CopyStream(input, manifest.InputStream); } stream.Position = 0L; string fullName = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All); if (string.IsNullOrEmpty(fullName)) { fullName = manifest.GetType().Name; } Util.WriteLogFile(fullName + ".read.xml", stream); } finally { stream.Close(); } Util.WriteLog(string.Format(CultureInfo.InvariantCulture, "ManifestReader.ReadManifest t={0}", new object[] { Environment.TickCount - tickCount })); manifest.OnAfterLoad(); return(manifest); }
private static Stream Serialize(Manifest manifest) { manifest.OnBeforeSave(); var m = new MemoryStream(); var s = new XmlSerializer(manifest.GetType()); var w = new StreamWriter(m); int t1 = Environment.TickCount; s.Serialize(w, manifest); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.Serialize t={0}", Environment.TickCount - t1)); w.Flush(); m.Position = 0; return(m); }
public static Stream Read(string path) { if (path == null) { throw new ArgumentNullException("path"); } if (!path.EndsWith(".manifest", StringComparison.Ordinal) && !path.EndsWith(".dll", StringComparison.Ordinal)) { return(null); } int tickCount = Environment.TickCount; EmbeddedManifestReader reader = new EmbeddedManifestReader(path); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "EmbeddedManifestReader.Read t={0}", new object[] { Environment.TickCount - tickCount })); return(reader.manifest); }
public static Stream XslTransform(string resource, Stream input, params DictionaryEntry[] entries) { int tickCount = Environment.TickCount; Stream embeddedResourceStream = Util.GetEmbeddedResourceStream(resource); int num2 = Environment.TickCount; XPathDocument stylesheet = new XPathDocument(embeddedResourceStream); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "new XPathDocument(1) t={1}", new object[] { resource, Environment.TickCount - num2 })); int num3 = Environment.TickCount; System.Xml.Xsl.XslTransform transform = new System.Xml.Xsl.XslTransform(); transform.Load(stylesheet, resolver, evidence); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "XslTransform.Load t={1}", new object[] { resource, Environment.TickCount - num3 })); MemoryStream output = new MemoryStream(); Util.CopyStream(input, output); int num4 = Environment.TickCount; XPathDocument document2 = new XPathDocument(output); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "new XPathDocument(2) t={1}", new object[] { resource, Environment.TickCount - num4 })); XsltArgumentList args = null; if (entries.Length > 0) { args = new XsltArgumentList(); foreach (DictionaryEntry entry in entries) { string name = entry.Key.ToString(); object parameter = entry.Value.ToString(); args.AddParam(name, "", parameter); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "arg: key='{0}' value='{1}'", new object[] { name, parameter.ToString() })); } } MemoryStream w = new MemoryStream(); XmlTextWriter writer = new XmlTextWriter(w, Encoding.UTF8); writer.WriteStartDocument(); int num1 = Environment.TickCount; transform.Transform((IXPathNavigable)document2, args, (XmlWriter)writer, resolver); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "XslTransform.Transform t={1}", new object[] { resource, Environment.TickCount - num4 })); writer.WriteEndDocument(); writer.Flush(); w.Position = 0L; Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "XslTransform(\"{0}\") t={1}", new object[] { resource, Environment.TickCount - tickCount })); return(w); }
public static Stream Read(string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (!path.EndsWith(".manifest", StringComparison.Ordinal) && !path.EndsWith(".dll", StringComparison.Ordinal)) { // Everything that does not end with .dll or .manifest is not a valid native assembly (this includes // EXEs with ID1 manifest) return(null); } int t1 = Environment.TickCount; EmbeddedManifestReader r = new EmbeddedManifestReader(path); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "EmbeddedManifestReader.Read t={0}", Environment.TickCount - t1)); return(r._manifest); }
private static Manifest Deserialize(Stream s) { s.Position = 0L; XmlTextReader reader = new XmlTextReader(s); do { reader.Read(); }while (reader.NodeType != XmlNodeType.Element); string str = typeof(Util).Namespace; Type type = Type.GetType(string.Format(CultureInfo.InvariantCulture, "{0}.{1}", new object[] { str, reader.Name })); s.Position = 0L; XmlSerializer serializer = new XmlSerializer(type); int tickCount = Environment.TickCount; Manifest manifest = (Manifest)serializer.Deserialize(s); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestReader.Deserialize t={0}", new object[] { Environment.TickCount - tickCount })); return(manifest); }
public static Stream XslTransform(string resource, Stream input, params DictionaryEntry[] entries) { int t1 = Environment.TickCount; Stream s = Util.GetEmbeddedResourceStream(resource); int t2 = Environment.TickCount; XPathDocument d = new XPathDocument(s); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "new XPathDocument(1) t={0}", Environment.TickCount - t2)); int t3 = Environment.TickCount; XslCompiledTransform xslc = new XslCompiledTransform(); // Using the Trusted Xslt is fine as the style sheet comes from our own assemblies. // This is similar to the prior this.GetType().Assembly/Evidence method that was used in the now depricated XslTransform. xslc.Load(d, XsltSettings.TrustedXslt, s_resolver); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "XslCompiledTransform.Load t={0}", Environment.TickCount - t3)); // Need to copy input stream because XmlReader will close it, // causing errors for later callers that access the same stream MemoryStream clonedInput = new MemoryStream(); Util.CopyStream(input, clonedInput); int t4 = Environment.TickCount; XmlReader xml = XmlReader.Create(clonedInput); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "new XmlReader(2) t={0}", Environment.TickCount - t4)); XsltArgumentList args = null; if (entries.Length > 0) { args = new XsltArgumentList(); foreach (DictionaryEntry entry in entries) { string key = entry.Key.ToString(); object val = entry.Value.ToString(); args.AddParam(key, "", val); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "arg: key='{0}' value='{1}'", key, val.ToString())); } } MemoryStream m = new MemoryStream(); XmlTextWriter w = new XmlTextWriter(m, Encoding.UTF8); w.WriteStartDocument(); int t5 = Environment.TickCount; xslc.Transform(xml, args, w, s_resolver); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "XslCompiledTransform.Transform t={0}", Environment.TickCount - t4)); w.WriteEndDocument(); w.Flush(); m.Position = 0; Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "XslCompiledTransform(\"{0}\") t={1}", resource, Environment.TickCount - t1)); return(m); }
/// <summary> /// Updates an existing ClickOnce application manifest with the specified trust. /// </summary> /// <param name="input">Specifies an input stream.</param> /// <param name="output">Specifies an output stream.</param> public void WriteManifest(Stream input, Stream output) { int t1 = Environment.TickCount; XmlDocument document = new XmlDocument(); XmlReaderSettings xrSettings = new XmlReaderSettings(); xrSettings.DtdProcessing = DtdProcessing.Ignore; using (XmlReader xr = XmlReader.Create(input, xrSettings)) { document.Load(xr); } XmlNamespaceManager nsmgr = XmlNamespaces.GetNamespaceManager(document.NameTable); XmlElement assemblyElement = (XmlElement)document.SelectSingleNode(XPaths.assemblyElement, nsmgr); if (assemblyElement == null) { throw new BadImageFormatException(); } XmlElement trustInfoElement = (XmlElement)assemblyElement.SelectSingleNode(XPaths.trustInfoElement, nsmgr); if (trustInfoElement == null) { trustInfoElement = document.CreateElement(XmlUtil.TrimPrefix(XPaths.trustInfoElement), XmlNamespaces.asmv2); assemblyElement.AppendChild(trustInfoElement); } // If we have an input trustinfo document and no output specified then just copy the input to the output if (_inputTrustInfoDocument != null && _outputPermissionSet == null && !_sameSiteChanged) { XmlElement newTrustInfoElement = (XmlElement)document.ImportNode(_inputTrustInfoDocument.DocumentElement, true); trustInfoElement.ParentNode.ReplaceChild(newTrustInfoElement, trustInfoElement); } else { XmlElement securityElement = (XmlElement)trustInfoElement.SelectSingleNode(XPaths.securityElement, nsmgr); if (securityElement == null) { securityElement = document.CreateElement(XmlUtil.TrimPrefix(XPaths.securityElement), XmlNamespaces.asmv2); trustInfoElement.AppendChild(securityElement); } XmlElement applicationRequestMinimumElement = (XmlElement)securityElement.SelectSingleNode(XPaths.applicationRequestMinimumElement, nsmgr); if (applicationRequestMinimumElement == null) { applicationRequestMinimumElement = document.CreateElement(XmlUtil.TrimPrefix(XPaths.applicationRequestMinimumElement), XmlNamespaces.asmv2); securityElement.AppendChild(applicationRequestMinimumElement); } XmlNodeList permissionSetNodes = applicationRequestMinimumElement.SelectNodes(XPaths.permissionSetElement, nsmgr); foreach (XmlNode permissionSetNode in permissionSetNodes) { applicationRequestMinimumElement.RemoveChild(permissionSetNode); } XmlDocument permissionSetDocument = GetOutputPermissionSetDocument(); XmlElement permissionSetElement = (XmlElement)document.ImportNode(permissionSetDocument.DocumentElement, true); applicationRequestMinimumElement.AppendChild(permissionSetElement); FixupPermissionSetElement(permissionSetElement); } // Truncate any contents that may be in the file if (output.Length > 0) { output.SetLength(0); output.Flush(); } document.Save(output); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteTrustInfo t={0}", Environment.TickCount - t1)); }
private void ValidateCom() { int t1 = Environment.TickCount; string outputFileName = Path.GetFileName(SourcePath); Dictionary <string, ComInfo> clsidList = new Dictionary <string, ComInfo>(); Dictionary <string, ComInfo> tlbidList = new Dictionary <string, ComInfo>(); // Check for duplicate COM definitions in all dependent manifests... foreach (AssemblyReference assembly in AssemblyReferences) { if (assembly.ReferenceType == AssemblyReferenceType.NativeAssembly && !assembly.IsPrerequisite && !String.IsNullOrEmpty(assembly.ResolvedPath)) { ComInfo[] comInfoArray = ManifestReader.GetComInfo(assembly.ResolvedPath);; if (comInfoArray != null) { foreach (ComInfo comInfo in comInfoArray) { if (!String.IsNullOrEmpty(comInfo.ClsId)) { string key = comInfo.ClsId.ToLowerInvariant(); if (!clsidList.ContainsKey(key)) { clsidList.Add(key, comInfo); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "clsid", comInfo.ComponentFileName, comInfo.ClsId, comInfo.ManifestFileName, clsidList[key].ManifestFileName); } } if (!String.IsNullOrEmpty(comInfo.TlbId)) { string key = comInfo.TlbId.ToLowerInvariant(); if (!tlbidList.ContainsKey(key)) { tlbidList.Add(key, comInfo); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "tlbid", comInfo.ComponentFileName, comInfo.TlbId, comInfo.ManifestFileName, tlbidList[key].ManifestFileName); } } } } } } // Check for duplicate COM definitions in the manifest about to be generated... foreach (FileReference file in FileReferences) { if (file.ComClasses != null) { foreach (ComClass comClass in file.ComClasses) { string key = comClass.ClsId.ToLowerInvariant(); if (!clsidList.ContainsKey(key)) { clsidList.Add(key, new ComInfo(outputFileName, file.TargetPath, comClass.ClsId, null)); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "clsid", file.ToString(), comClass.ClsId, outputFileName, clsidList[key].ManifestFileName); } } } if (file.TypeLibs != null) { foreach (TypeLib typeLib in file.TypeLibs) { string key = typeLib.TlbId.ToLowerInvariant(); if (!tlbidList.ContainsKey(key)) { tlbidList.Add(key, new ComInfo(outputFileName, file.TargetPath, null, typeLib.TlbId)); } else { OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", "tlbid", file.ToString(), typeLib.TlbId, outputFileName, tlbidList[key].ManifestFileName); } } } } Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "GenerateManifest.CheckForComDuplicates t={0}", Environment.TickCount - t1)); }
public static void WriteManifest(Manifest manifest, Stream output) { int tickCount = Environment.TickCount; Stream s = Serialize(manifest); string fullName = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All); if (string.IsNullOrEmpty(fullName)) { fullName = manifest.GetType().Name; } Util.WriteLogFile(fullName + ".write.0-serialized.xml", s); string resource = "write2.xsl"; Stream stream2 = null; if (manifest.GetType() == typeof(ApplicationManifest)) { ApplicationManifest manifest2 = (ApplicationManifest)manifest; if (manifest2.TrustInfo == null) { stream2 = XmlUtil.XslTransform(resource, s, new DictionaryEntry[0]); } else { string temporaryFile = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile(); manifest2.TrustInfo.Write(temporaryFile); if (Util.logging) { try { File.Copy(temporaryFile, Path.Combine(Util.logPath, fullName + ".trust-file.xml"), true); } catch (IOException) { } catch (ArgumentException) { } catch (UnauthorizedAccessException) { } catch (NotSupportedException) { } } DictionaryEntry entry = new DictionaryEntry("trust-file", temporaryFile); try { DictionaryEntry[] entries = new DictionaryEntry[] { entry }; stream2 = XmlUtil.XslTransform(resource, s, entries); } finally { File.Delete(temporaryFile); } } } else { stream2 = XmlUtil.XslTransform(resource, s, new DictionaryEntry[0]); } Util.WriteLogFile(fullName + ".write.1-transformed.xml", stream2); Stream stream3 = null; if (manifest.InputStream == null) { stream3 = stream2; } else { string str4 = Util.WriteTempFile(manifest.InputStream); DictionaryEntry entry2 = new DictionaryEntry("base-file", str4); try { DictionaryEntry[] entryArray2 = new DictionaryEntry[] { entry2 }; stream3 = XmlUtil.XslTransform("merge.xsl", stream2, entryArray2); } finally { File.Delete(str4); } Util.WriteLogFile(fullName + ".write.2-merged.xml", stream3); } Stream stream4 = ManifestFormatter.Format(stream3); Util.WriteLogFile(fullName + ".write.3-formatted.xml", stream4); Util.CopyStream(stream4, output); Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteManifest t={0}", new object[] { Environment.TickCount - tickCount })); }
private void ValidateReferencesForClickOnceApplication() { int t1 = Environment.TickCount; bool isPartialTrust = !TrustInfo.IsFullTrust; Dictionary <string, NGen <bool> > targetPathList = new Dictionary <string, NGen <bool> >(); foreach (AssemblyReference assembly in AssemblyReferences) { // Check all resolved dependencies for partial trust apps... if (isPartialTrust && (assembly != EntryPoint) && !String.IsNullOrEmpty(assembly.ResolvedPath)) { ValidateReferenceForPartialTrust(assembly, TrustInfo); } // Check TargetPath for all local dependencies, ignoring any Prerequisites if (!assembly.IsPrerequisite && !String.IsNullOrEmpty(assembly.TargetPath)) { // Check target path does not exceed maximum... if (_maxTargetPath > 0 && assembly.TargetPath.Length > _maxTargetPath) { OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", assembly.ToString(), _maxTargetPath.ToString(CultureInfo.CurrentCulture)); } // Check for two or more items with the same TargetPath... string key = assembly.TargetPath.ToLowerInvariant(); if (!targetPathList.ContainsKey(key)) { targetPathList.Add(key, false); } else if (targetPathList[key] == false) { OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", assembly.ToString()); targetPathList[key] = true; // only warn once per path } } else { // Check assembly name does not exceed maximum... if (_maxTargetPath > 0 && assembly.AssemblyIdentity.Name.Length > _maxTargetPath) { OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", assembly.AssemblyIdentity.Name, _maxTargetPath.ToString(CultureInfo.CurrentCulture)); } } // Check that all prerequisites are strong named... if (assembly.IsPrerequisite && !assembly.AssemblyIdentity.IsStrongName && !assembly.IsVirtual) { OutputMessages.AddErrorMessage("GenerateManifest.PrerequisiteNotSigned", assembly.ToString()); } } foreach (FileReference file in FileReferences) { // Check that file is not an assembly... if (!String.IsNullOrEmpty(file.ResolvedPath) && PathUtil.IsAssembly(file.ResolvedPath)) { OutputMessages.AddWarningMessage("GenerateManifest.AssemblyAsFile", file.ToString()); } if (!String.IsNullOrEmpty(file.TargetPath)) { // Check target path does not exceed maximum... if (_maxTargetPath > 0 && file.TargetPath.Length > _maxTargetPath) { OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", file.TargetPath, _maxTargetPath.ToString(CultureInfo.CurrentCulture)); } // Check for two or more items with the same TargetPath... string key = file.TargetPath.ToLowerInvariant(); if (!targetPathList.ContainsKey(key)) { targetPathList.Add(key, false); } else if (targetPathList[key] == false) { OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", file.TargetPath); targetPathList[key] = true; // only warn once per path } } } Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "GenerateManifest.CheckManifestReferences t={0}", Environment.TickCount - t1)); }
private static void WriteManifest(Manifest manifest, Stream output, string targetframeWorkVersion) { int t1 = Environment.TickCount; Stream s1 = Serialize(manifest); string n = manifest.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All); if (String.IsNullOrEmpty(n)) { n = manifest.GetType().Name; } Util.WriteLogFile(n + ".write.0-serialized.xml", s1); string resource; if (string.IsNullOrEmpty(targetframeWorkVersion) || Util.CompareFrameworkVersions(targetframeWorkVersion, Constants.TargetFrameworkVersion40) <= 0) { resource = "write2.xsl"; } else { resource = "write3.xsl"; } Stream s2; if (manifest.GetType() == typeof(ApplicationManifest)) { var am = (ApplicationManifest)manifest; if (am.TrustInfo == null) { s2 = XmlUtil.XslTransform(resource, s1); } else { // May throw IO-related exceptions string temp = FileUtilities.GetTemporaryFile(); am.TrustInfo.Write(temp); if (Util.logging) { try { File.Copy(temp, Path.Combine(Util.logPath, n + ".trust-file.xml"), true); } catch (IOException) { } catch (ArgumentException) { } catch (UnauthorizedAccessException) { } catch (NotSupportedException) { } } var arg = new DictionaryEntry("trust-file", temp); try { s2 = XmlUtil.XslTransform(resource, s1, arg); } finally { File.Delete(temp); } } } else { s2 = XmlUtil.XslTransform(resource, s1); } Util.WriteLogFile(n + ".write.1-transformed.xml", s2); Stream s3; if (manifest.InputStream == null) { s3 = s2; } else { string temp = Util.WriteTempFile(manifest.InputStream); var arg = new DictionaryEntry("base-file", temp); try { s3 = XmlUtil.XslTransform("merge.xsl", s2, arg); } finally { File.Delete(temp); } Util.WriteLogFile(n + ".write.2-merged.xml", s3); } Stream s4 = ManifestFormatter.Format(s3); Util.WriteLogFile(n + ".write.3-formatted.xml", s4); Util.CopyStream(s4, output); Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.WriteManifest t={0}", Environment.TickCount - t1)); }
public static Stream Format(Stream input) { int t1 = Environment.TickCount; XmlTextReader r = new XmlTextReader(input); r.DtdProcessing = DtdProcessing.Ignore; r.WhitespaceHandling = WhitespaceHandling.None; XmlNamespaceManager nsmgr = XmlNamespaces.GetNamespaceManager(r.NameTable); MemoryStream m = new MemoryStream(); XmlTextWriter w = new XmlTextWriter(m, Encoding.UTF8); w.Formatting = Formatting.Indented; w.Indentation = 2; w.WriteStartDocument(); while (r.Read()) { switch (r.NodeType) { case XmlNodeType.Element: w.WriteStartElement(r.Prefix, r.LocalName, r.NamespaceURI); if (r.HasAttributes) { string elementQName = XmlUtil.GetQName(r, nsmgr); for (int i = 0; i < r.AttributeCount; ++i) { r.MoveToAttribute(i); string attributeQName = XmlUtil.GetQName(r, nsmgr); string xpath = elementQName + "/@" + attributeQName; // Filter out language="*" if ((xpath.Equals(XPaths.languageAttribute1, StringComparison.Ordinal) || xpath.Equals(XPaths.languageAttribute2, StringComparison.Ordinal)) && String.Equals(r.Value, "*", StringComparison.Ordinal)) { continue; } // Filter out attributes with empty values if attribute is on the list... if (String.IsNullOrEmpty(r.Value) && Array.BinarySearch(XPaths.emptyAttributeList, xpath) >= 0) { continue; } w.WriteAttributeString(r.Prefix, r.LocalName, r.NamespaceURI, r.Value); } r.MoveToElement(); //Moves the reader back to the element node. } if (r.IsEmptyElement) { w.WriteEndElement(); } break; case XmlNodeType.EndElement: w.WriteEndElement(); break; case XmlNodeType.Comment: w.WriteComment(r.Value); break; case XmlNodeType.CDATA: w.WriteCData(r.Value); break; case XmlNodeType.Text: w.WriteString(r.Value); break; } } w.WriteEndDocument(); w.Flush(); m.Position = 0; Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "ManifestWriter.Format t={0}", Environment.TickCount - t1)); return(m); }
public static Stream Format(Stream input) { int tickCount = Environment.TickCount; XmlTextReader r = new XmlTextReader(input) { WhitespaceHandling = WhitespaceHandling.None }; XmlNamespaceManager namespaceManager = XmlNamespaces.GetNamespaceManager(r.NameTable); MemoryStream w = new MemoryStream(); XmlTextWriter writer = new XmlTextWriter(w, Encoding.UTF8) { Formatting = Formatting.Indented, Indentation = 2 }; writer.WriteStartDocument(); while (r.Read()) { string str; int num2; switch (r.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(r.Prefix, r.LocalName, r.NamespaceURI); if (!r.HasAttributes) { goto Label_0162; } str = XmlUtil.GetQName(r, namespaceManager); num2 = 0; goto Label_014E; case XmlNodeType.Attribute: { continue; } case XmlNodeType.Text: { writer.WriteString(r.Value); continue; } case XmlNodeType.CDATA: { writer.WriteCData(r.Value); continue; } case XmlNodeType.Comment: { writer.WriteComment(r.Value); continue; } case XmlNodeType.EndElement: { writer.WriteEndElement(); continue; } default: { continue; } } Label_00BB: r.MoveToAttribute(num2); string qName = XmlUtil.GetQName(r, namespaceManager); string str3 = str + "/@" + qName; if (((!str3.Equals("asmv1:assemblyIdentity/@language", StringComparison.Ordinal) && !str3.Equals("asmv2:assemblyIdentity/@language", StringComparison.Ordinal)) || !string.Equals(r.Value, "*", StringComparison.Ordinal)) && (!string.IsNullOrEmpty(r.Value) || (Array.BinarySearch <string>(XPaths.emptyAttributeList, str3) < 0))) { writer.WriteAttributeString(r.Prefix, r.LocalName, r.NamespaceURI, r.Value); } num2++; Label_014E: if (num2 < r.AttributeCount) { goto Label_00BB; } r.MoveToElement(); Label_0162: if (r.IsEmptyElement) { writer.WriteEndElement(); } } writer.WriteEndDocument(); writer.Flush(); w.Position = 0L; Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "ManifestWriter.Format t={0}", new object[] { Environment.TickCount - tickCount })); return(w); }
private void ValidateReferencesForClickOnceApplication() { int tickCount = Environment.TickCount; bool flag = !this.TrustInfo.IsFullTrust; Dictionary <string, NGen <bool> > dictionary = new Dictionary <string, NGen <bool> >(); foreach (AssemblyReference reference in base.AssemblyReferences) { if ((flag && (reference != this.EntryPoint)) && !string.IsNullOrEmpty(reference.ResolvedPath)) { this.ValidateReferenceForPartialTrust(reference, this.TrustInfo); } if (!reference.IsPrerequisite && !string.IsNullOrEmpty(reference.TargetPath)) { if ((this.maxTargetPath > 0) && (reference.TargetPath.Length > this.maxTargetPath)) { base.OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", new string[] { reference.ToString(), this.maxTargetPath.ToString(CultureInfo.CurrentCulture) }); } string key = reference.TargetPath.ToLowerInvariant(); if (!dictionary.ContainsKey(key)) { dictionary.Add(key, 0); } else if (dictionary[key] == 0) { base.OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", new string[] { reference.ToString() }); dictionary[key] = 1; } } else if ((this.maxTargetPath > 0) && (reference.AssemblyIdentity.Name.Length > this.maxTargetPath)) { base.OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", new string[] { reference.AssemblyIdentity.Name, this.maxTargetPath.ToString(CultureInfo.CurrentCulture) }); } if ((reference.IsPrerequisite && !reference.AssemblyIdentity.IsStrongName) && !reference.IsVirtual) { base.OutputMessages.AddErrorMessage("GenerateManifest.PrerequisiteNotSigned", new string[] { reference.ToString() }); } } foreach (FileReference reference2 in base.FileReferences) { if (!string.IsNullOrEmpty(reference2.ResolvedPath) && PathUtil.IsAssembly(reference2.ResolvedPath)) { base.OutputMessages.AddWarningMessage("GenerateManifest.AssemblyAsFile", new string[] { reference2.ToString() }); } if (!string.IsNullOrEmpty(reference2.TargetPath)) { if ((this.maxTargetPath > 0) && (reference2.TargetPath.Length > this.maxTargetPath)) { base.OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", new string[] { reference2.TargetPath, this.maxTargetPath.ToString(CultureInfo.CurrentCulture) }); } string str2 = reference2.TargetPath.ToLowerInvariant(); if (!dictionary.ContainsKey(str2)) { dictionary.Add(str2, 0); } else if (dictionary[str2] == 0) { base.OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", new string[] { reference2.TargetPath }); dictionary[str2] = 1; } } } Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "GenerateManifest.CheckManifestReferences t={0}", new object[] { Environment.TickCount - tickCount })); }
private void ValidateCom() { int tickCount = Environment.TickCount; string fileName = Path.GetFileName(base.SourcePath); Dictionary <string, ComInfo> dictionary = new Dictionary <string, ComInfo>(); Dictionary <string, ComInfo> dictionary2 = new Dictionary <string, ComInfo>(); foreach (AssemblyReference reference in base.AssemblyReferences) { if (((reference.ReferenceType == AssemblyReferenceType.NativeAssembly) && !reference.IsPrerequisite) && !string.IsNullOrEmpty(reference.ResolvedPath)) { ComInfo[] comInfo = ManifestReader.GetComInfo(reference.ResolvedPath); if (comInfo != null) { foreach (ComInfo info in comInfo) { if (!string.IsNullOrEmpty(info.ClsId)) { string key = info.ClsId.ToLowerInvariant(); if (!dictionary.ContainsKey(key)) { dictionary.Add(key, info); } else { base.OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", new string[] { "clsid", info.ComponentFileName, info.ClsId, info.ManifestFileName, dictionary[key].ManifestFileName }); } } if (!string.IsNullOrEmpty(info.TlbId)) { string str3 = info.TlbId.ToLowerInvariant(); if (!dictionary2.ContainsKey(str3)) { dictionary2.Add(str3, info); } else { base.OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", new string[] { "tlbid", info.ComponentFileName, info.TlbId, info.ManifestFileName, dictionary2[str3].ManifestFileName }); } } } } } } foreach (FileReference reference2 in base.FileReferences) { if (reference2.ComClasses != null) { foreach (ComClass class2 in reference2.ComClasses) { string str4 = class2.ClsId.ToLowerInvariant(); if (!dictionary.ContainsKey(str4)) { dictionary.Add(str4, new ComInfo(fileName, reference2.TargetPath, class2.ClsId, null)); } else { base.OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", new string[] { "clsid", reference2.ToString(), class2.ClsId, fileName, dictionary[str4].ManifestFileName }); } } } if (reference2.TypeLibs != null) { foreach (TypeLib lib in reference2.TypeLibs) { string str5 = lib.TlbId.ToLowerInvariant(); if (!dictionary2.ContainsKey(str5)) { dictionary2.Add(str5, new ComInfo(fileName, reference2.TargetPath, null, lib.TlbId)); } else { base.OutputMessages.AddErrorMessage("GenerateManifest.DuplicateComDefinition", new string[] { "tlbid", reference2.ToString(), lib.TlbId, fileName, dictionary2[str5].ManifestFileName }); } } } } Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "GenerateManifest.CheckForComDuplicates t={0}", new object[] { Environment.TickCount - tickCount })); }