private static void UpdateFileReference(BaseReference f, string targetFrameworkVersion) { if (String.IsNullOrEmpty(f.ResolvedPath)) { throw new FileNotFoundException(null, f.SourcePath); } string hash; long size; if (string.IsNullOrEmpty(targetFrameworkVersion)) { Util.GetFileInfo(f.ResolvedPath, out hash, out size); } else { Util.GetFileInfo(f.ResolvedPath, targetFrameworkVersion, out hash, out size); } f.Hash = hash; f.Size = size; if (String.IsNullOrEmpty(f.TargetPath)) { if (!String.IsNullOrEmpty(f.SourcePath)) { f.TargetPath = BaseReference.GetDefaultTargetPath(f.SourcePath); } else { f.TargetPath = BaseReference.GetDefaultTargetPath(Path.GetFileName(f.ResolvedPath)); } } }
internal static void UpdateEntryPoint(string inputPath, string outputPath, string updatedApplicationPath, string applicationManifestPath) { string str2; long num; XmlDocument document = new XmlDocument(); document.Load(inputPath); XmlNamespaceManager namespaceManager = XmlNamespaces.GetNamespaceManager(document.NameTable); Microsoft.Build.Tasks.Deployment.ManifestUtilities.AssemblyIdentity identity = Microsoft.Build.Tasks.Deployment.ManifestUtilities.AssemblyIdentity.FromManifest(applicationManifestPath); XmlNode node = null; foreach (string str in XPaths.codebasePaths) { node = document.SelectSingleNode(str, namespaceManager); if (node != null) { break; } } if (node == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "XPath not found: {0}", new object[] { XPaths.codebasePaths[0] })); } node.Value = updatedApplicationPath; XmlNode node2 = ((XmlAttribute)node).OwnerElement.SelectSingleNode("asmv2:assemblyIdentity/@publicKeyToken", namespaceManager); if (node2 == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "XPath not found: {0}", new object[] { "asmv2:assemblyIdentity/@publicKeyToken" })); } node2.Value = identity.PublicKeyToken; Util.GetFileInfo(applicationManifestPath, out str2, out num); XmlNode node3 = ((XmlAttribute)node).OwnerElement.SelectSingleNode("asmv2:hash/dsig:DigestValue", namespaceManager); if (node3 != null) { ((XmlElement)node3).InnerText = str2; } XmlAttribute attribute = ((XmlAttribute)node).OwnerElement.Attributes[XmlUtil.TrimPrefix("asmv2:size")]; if (attribute == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "XPath not found: {0}", new object[] { "asmv2:size" })); } attribute.Value = num.ToString(CultureInfo.InvariantCulture); document.Save(outputPath); }
private static void UpdateFileReference(BaseReference f) { string str; long num; if (string.IsNullOrEmpty(f.ResolvedPath)) { throw new FileNotFoundException(null, f.SourcePath); } Util.GetFileInfo(f.ResolvedPath, out str, out num); f.Hash = str; f.Size = num; if (string.IsNullOrEmpty(f.TargetPath)) { if (!string.IsNullOrEmpty(f.SourcePath)) { f.TargetPath = BaseReference.GetDefaultTargetPath(f.SourcePath); } else { f.TargetPath = BaseReference.GetDefaultTargetPath(Path.GetFileName(f.ResolvedPath)); } } }
internal static void UpdateEntryPoint(string inputPath, string outputPath, string updatedApplicationPath, string applicationManifestPath, string targetFrameworkVersion) { XmlDocument document = new XmlDocument(); XmlReaderSettings xrSettings = new XmlReaderSettings(); xrSettings.DtdProcessing = DtdProcessing.Ignore; using (XmlReader xr = XmlReader.Create(inputPath, xrSettings)) { document.Load(xr); } XmlNamespaceManager nsmgr = XmlNamespaces.GetNamespaceManager(document.NameTable); AssemblyIdentity appManifest = AssemblyIdentity.FromManifest(applicationManifestPath); // update path to application manifest XmlNode codeBaseNode = null; foreach (string xpath in XPaths.codebasePaths) { codeBaseNode = document.SelectSingleNode(xpath, nsmgr); if (codeBaseNode != null) { break; } } if (codeBaseNode == null) { throw new InvalidOperationException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "XPath not found: {0}", XPaths.codebasePaths[0])); } codeBaseNode.Value = updatedApplicationPath; // update Public key token of application manifest XmlNode publicKeyTokenNode = ((XmlAttribute)codeBaseNode).OwnerElement.SelectSingleNode(XPaths.dependencyPublicKeyTokenAttribute, nsmgr); if (publicKeyTokenNode == null) { throw new InvalidOperationException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "XPath not found: {0}", XPaths.dependencyPublicKeyTokenAttribute)); } publicKeyTokenNode.Value = appManifest.PublicKeyToken; // update hash of application manifest string hash; long size; Util.GetFileInfo(applicationManifestPath, targetFrameworkVersion, out hash, out size); // Hash node may not be present with optional signing XmlNode hashNode = ((XmlAttribute)codeBaseNode).OwnerElement.SelectSingleNode(XPaths.hashElement, nsmgr); if (hashNode != null) { ((XmlElement)hashNode).InnerText = hash; } // update file size of application manifest XmlAttribute sizeAttribute = ((XmlAttribute)codeBaseNode).OwnerElement.Attributes[XmlUtil.TrimPrefix(XPaths.fileSizeAttribute)]; if (sizeAttribute == null) { throw new InvalidOperationException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "XPath not found: {0}", XPaths.fileSizeAttribute)); } sizeAttribute.Value = size.ToString(System.Globalization.CultureInfo.InvariantCulture); document.Save(outputPath); }