private void ValidateEntryPoint() { if (this.entryPoint != null) { if (!string.IsNullOrEmpty(this.entryPoint.TargetPath) && !this.entryPoint.TargetPath.EndsWith(".manifest", StringComparison.OrdinalIgnoreCase)) { base.OutputMessages.AddErrorMessage("GenerateManifest.InvalidEntryPoint", new string[] { this.entryPoint.ToString() }); } string resolvedPath = this.entryPoint.ResolvedPath; if (resolvedPath == null) { resolvedPath = Path.Combine(Path.GetDirectoryName(base.SourcePath), this.entryPoint.TargetPath); } if (File.Exists(resolvedPath)) { ApplicationManifest manifest = ManifestReader.ReadManifest(resolvedPath, false) as ApplicationManifest; if (manifest != null) { if (this.Install) { if (manifest.HostInBrowser) { base.OutputMessages.AddErrorMessage("GenerateManifest.HostInBrowserNotOnlineOnly", new string[0]); } } else if ((manifest.FileAssociations != null) && (manifest.FileAssociations.Count > 0)) { base.OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationsNotInstalled", new string[0]); } } } } }
private bool AddClickOnceFiles(ApplicationManifest manifest) { int tickCount = Environment.TickCount; if ((this.ConfigFile != null) && !string.IsNullOrEmpty(this.ConfigFile.ItemSpec)) { manifest.ConfigFile = base.FindFileFromItem(this.ConfigFile).TargetPath; } if ((this.IconFile != null) && !string.IsNullOrEmpty(this.IconFile.ItemSpec)) { manifest.IconFile = base.FindFileFromItem(this.IconFile).TargetPath; } if ((this.TrustInfoFile != null) && !string.IsNullOrEmpty(this.TrustInfoFile.ItemSpec)) { manifest.TrustInfo = new TrustInfo(); manifest.TrustInfo.Read(this.TrustInfoFile.ItemSpec); } if (manifest.TrustInfo == null) { manifest.TrustInfo = new TrustInfo(); } if (this.OSVersion != null) { manifest.OSVersion = this.osVersion; } if (this.ClrVersion != null) { AssemblyReference assembly = manifest.AssemblyReferences.Find("Microsoft.Windows.CommonLanguageRuntime"); if (assembly == null) { assembly = new AssemblyReference { IsPrerequisite = true }; manifest.AssemblyReferences.Add(assembly); } assembly.AssemblyIdentity = new AssemblyIdentity("Microsoft.Windows.CommonLanguageRuntime", this.ClrVersion); } if (Util.CompareFrameworkVersions(base.TargetFrameworkVersion, "v3.0") == 0) { this.EnsureAssemblyReferenceExists(manifest, this.CreateAssemblyIdentity(Constants.NET30AssemblyIdentity)); } else if (Util.CompareFrameworkVersions(base.TargetFrameworkVersion, "v3.5") == 0) { this.EnsureAssemblyReferenceExists(manifest, this.CreateAssemblyIdentity(Constants.NET30AssemblyIdentity)); this.EnsureAssemblyReferenceExists(manifest, this.CreateAssemblyIdentity(Constants.NET35AssemblyIdentity)); if ((!string.IsNullOrEmpty(this.TargetFrameworkSubset) && this.TargetFrameworkSubset.Equals("Client", StringComparison.OrdinalIgnoreCase)) || (!string.IsNullOrEmpty(this.TargetFrameworkProfile) && this.TargetFrameworkProfile.Equals("Client", StringComparison.OrdinalIgnoreCase))) { this.EnsureAssemblyReferenceExists(manifest, this.CreateAssemblyIdentity(Constants.NET35ClientAssemblyIdentity)); } else if (this.RequiresMinimumFramework35SP1) { this.EnsureAssemblyReferenceExists(manifest, this.CreateAssemblyIdentity(Constants.NET35SP1AssemblyIdentity)); } } Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "GenerateApplicationManifest.AddClickOnceFiles t={0}", new object[] { Environment.TickCount - tickCount })); return true; }
/// <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; string resource = "read2.xsl"; Manifest m = null; 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)) { ApplicationManifest 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 bool AddClickOnceFileAssociations(ApplicationManifest manifest) { if (this.FileAssociations != null) { foreach (ITaskItem item in this.FileAssociations) { FileAssociation fileAssociation = new FileAssociation { DefaultIcon = item.GetMetadata("DefaultIcon"), Description = item.GetMetadata("Description"), Extension = item.ItemSpec, ProgId = item.GetMetadata("Progid") }; manifest.FileAssociations.Add(fileAssociation); } } return true; }
private void ValidateEntryPoint() { if (_entryPoint != null) { if (!String.IsNullOrEmpty(_entryPoint.TargetPath) && !_entryPoint.TargetPath.EndsWith(".manifest", StringComparison.OrdinalIgnoreCase)) { OutputMessages.AddErrorMessage("GenerateManifest.InvalidEntryPoint", _entryPoint.ToString()); } string ManifestPath = _entryPoint.ResolvedPath; if (ManifestPath == null) { ManifestPath = Path.Combine(Path.GetDirectoryName(SourcePath), _entryPoint.TargetPath); } if (File.Exists(ManifestPath)) { ApplicationManifest entryPointManifest = ManifestReader.ReadManifest(ManifestPath, false) as ApplicationManifest; if (entryPointManifest != null) { if (Install) { if (entryPointManifest.HostInBrowser) { OutputMessages.AddErrorMessage("GenerateManifest.HostInBrowserNotOnlineOnly"); } } else { if (entryPointManifest.FileAssociations != null && entryPointManifest.FileAssociations.Count > 0) { OutputMessages.AddErrorMessage("GenerateManifest.FileAssociationsNotInstalled"); } } } } } }
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 EnsureAssemblyReferenceExists(ApplicationManifest manifest, AssemblyIdentity identity) { if (manifest.AssemblyReferences.Find(identity) == null) { AssemblyReference assembly = new AssemblyReference(); assembly.IsPrerequisite = true; assembly.AssemblyIdentity = identity; manifest.AssemblyReferences.Add(assembly); } }
private bool BuildResolvedSettings(ApplicationManifest manifest) { // Note: if changing the logic in this function, please update the logic in // GenerateDeploymentManifest.BuildResolvedSettings as well. if (Product != null) manifest.Product = Product; else if (String.IsNullOrEmpty(manifest.Product)) manifest.Product = Path.GetFileNameWithoutExtension(manifest.AssemblyIdentity.Name); Debug.Assert(!String.IsNullOrEmpty(manifest.Product)); if (Publisher != null) { manifest.Publisher = Publisher; } else if (String.IsNullOrEmpty(manifest.Publisher)) { string org = Util.GetRegisteredOrganization(); if (!String.IsNullOrEmpty(org)) manifest.Publisher = org; else manifest.Publisher = manifest.Product; } Debug.Assert(!String.IsNullOrEmpty(manifest.Publisher)); return true; }
private bool AddClickOnceFiles(ApplicationManifest manifest) { int t1 = Environment.TickCount; if (ConfigFile != null && !String.IsNullOrEmpty(ConfigFile.ItemSpec)) manifest.ConfigFile = FindFileFromItem(ConfigFile).TargetPath; if (IconFile != null && !String.IsNullOrEmpty(IconFile.ItemSpec)) manifest.IconFile = FindFileFromItem(IconFile).TargetPath; if (TrustInfoFile != null && !String.IsNullOrEmpty(TrustInfoFile.ItemSpec)) { manifest.TrustInfo = new TrustInfo(); manifest.TrustInfo.Read(TrustInfoFile.ItemSpec); } if (manifest.TrustInfo == null) manifest.TrustInfo = new TrustInfo(); if (OSVersion != null) { manifest.OSVersion = _osVersion; } if (ClrVersion != null) { AssemblyReference CLRPlatformAssembly = manifest.AssemblyReferences.Find(Constants.CLRPlatformAssemblyName); if (CLRPlatformAssembly == null) { CLRPlatformAssembly = new AssemblyReference(); CLRPlatformAssembly.IsPrerequisite = true; manifest.AssemblyReferences.Add(CLRPlatformAssembly); } CLRPlatformAssembly.AssemblyIdentity = new AssemblyIdentity(Constants.CLRPlatformAssemblyName, ClrVersion); } if (Util.CompareFrameworkVersions(TargetFrameworkVersion, Constants.TargetFrameworkVersion30) == 0) { EnsureAssemblyReferenceExists(manifest, CreateAssemblyIdentity(Constants.NET30AssemblyIdentity)); } else if (Util.CompareFrameworkVersions(TargetFrameworkVersion, Constants.TargetFrameworkVersion35) == 0) { EnsureAssemblyReferenceExists(manifest, CreateAssemblyIdentity(Constants.NET30AssemblyIdentity)); EnsureAssemblyReferenceExists(manifest, CreateAssemblyIdentity(Constants.NET35AssemblyIdentity)); if ((!String.IsNullOrEmpty(TargetFrameworkSubset) && TargetFrameworkSubset.Equals(Constants.ClientFrameworkSubset, StringComparison.OrdinalIgnoreCase)) || (!String.IsNullOrEmpty(TargetFrameworkProfile) && TargetFrameworkProfile.Equals(Constants.ClientFrameworkSubset, StringComparison.OrdinalIgnoreCase))) { EnsureAssemblyReferenceExists(manifest, CreateAssemblyIdentity(Constants.NET35ClientAssemblyIdentity)); } else if (RequiresMinimumFramework35SP1) { EnsureAssemblyReferenceExists(manifest, CreateAssemblyIdentity(Constants.NET35SP1AssemblyIdentity)); } } Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "GenerateApplicationManifest.AddClickOnceFiles t={0}", Environment.TickCount - t1)); return true; }
private bool AddIsolatedComReferences(ApplicationManifest manifest) { int t1 = Environment.TickCount; bool success = true; if (IsolatedComReferences != null) foreach (ITaskItem item in IsolatedComReferences) { string name = item.GetMetadata("Name"); if (String.IsNullOrEmpty(name)) name = Path.GetFileName(item.ItemSpec); FileReference file = AddFileFromItem(item); if (!file.ImportComComponent(item.ItemSpec, manifest.OutputMessages, name)) success = false; } Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "GenerateApplicationManifest.AddIsolatedComReferences t={0}", Environment.TickCount - t1)); return success; }
private bool BuildApplicationManifest(ApplicationManifest manifest) { if (Dependencies != null) foreach (ITaskItem item in Dependencies) AddAssemblyFromItem(item); if (Files != null) foreach (ITaskItem item in Files) AddFileFromItem(item); // Build ClickOnce info... manifest.IsClickOnceManifest = _manifestType == _ManifestType.ClickOnce; if (manifest.IsClickOnceManifest) { if (manifest.EntryPoint == null && Util.CompareFrameworkVersions(TargetFrameworkVersion, Constants.TargetFrameworkVersion35) < 0) { Log.LogErrorWithCodeFromResources("GenerateManifest.NoEntryPoint"); return false; } if (!AddClickOnceFiles(manifest)) return false; if (!AddClickOnceFileAssociations(manifest)) return false; } if (HostInBrowser && Util.CompareFrameworkVersions(TargetFrameworkVersion, Constants.TargetFrameworkVersion30) < 0) { Log.LogErrorWithCodeFromResources("GenerateManifest.HostInBrowserInvalidFrameworkVersion"); return false; } // Build isolated COM info... if (!AddIsolatedComReferences(manifest)) return false; manifest.MaxTargetPath = MaxTargetPath; manifest.HostInBrowser = HostInBrowser; manifest.UseApplicationTrust = UseApplicationTrust; if (UseApplicationTrust && SupportUrl != null) manifest.SupportUrl = SupportUrl; if (UseApplicationTrust && SuiteName != null) manifest.SuiteName = SuiteName; if (UseApplicationTrust && ErrorReportUrl != null) manifest.ErrorReportUrl = ErrorReportUrl; return true; }
/// <summary> /// /// </summary> /// <param name="manifest"></param> /// <param name="output"></param> /// <param name="targetframeWorkVersion">it will always use sha256 as signature algorithm if TFV is null</param> 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 = null; if (targetframeWorkVersion == null || targetframeWorkVersion.Length == 0 || Util.CompareFrameworkVersions(targetframeWorkVersion, Constants.TargetFrameworkVersion40) <= 0) { resource = "write2.xsl"; } else { resource = "write3.xsl"; } Stream s2 = null; if (manifest.GetType() == typeof(ApplicationManifest)) { ApplicationManifest 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) { } } DictionaryEntry 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 = null; if (manifest.InputStream == null) { s3 = s2; } else { string temp = Util.WriteTempFile(manifest.InputStream); DictionaryEntry 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)); }
private bool BuildResolvedSettings(ApplicationManifest manifest) { if (this.Product != null) { manifest.Product = this.Product; } else if (string.IsNullOrEmpty(manifest.Product)) { manifest.Product = Path.GetFileNameWithoutExtension(manifest.AssemblyIdentity.Name); } if (this.Publisher != null) { manifest.Publisher = this.Publisher; } else if (string.IsNullOrEmpty(manifest.Publisher)) { string registeredOrganization = Util.GetRegisteredOrganization(); if (!string.IsNullOrEmpty(registeredOrganization)) { manifest.Publisher = registeredOrganization; } else { manifest.Publisher = manifest.Product; } } return true; }
private bool BuildApplicationManifest(ApplicationManifest manifest) { if (this.Dependencies != null) { foreach (ITaskItem item in this.Dependencies) { base.AddAssemblyFromItem(item); } } if (this.Files != null) { foreach (ITaskItem item2 in this.Files) { base.AddFileFromItem(item2); } } manifest.IsClickOnceManifest = this.manifestType == _ManifestType.ClickOnce; if (manifest.IsClickOnceManifest) { if ((manifest.EntryPoint == null) && (Util.CompareFrameworkVersions(base.TargetFrameworkVersion, "v3.5") < 0)) { base.Log.LogErrorWithCodeFromResources("GenerateManifest.NoEntryPoint", new object[0]); return false; } if (!this.AddClickOnceFiles(manifest)) { return false; } if (!this.AddClickOnceFileAssociations(manifest)) { return false; } } if (this.HostInBrowser && (Util.CompareFrameworkVersions(base.TargetFrameworkVersion, "v3.0") < 0)) { base.Log.LogErrorWithCodeFromResources("GenerateManifest.HostInBrowserInvalidFrameworkVersion", new object[0]); return false; } if (!this.AddIsolatedComReferences(manifest)) { return false; } manifest.MaxTargetPath = base.MaxTargetPath; manifest.HostInBrowser = this.HostInBrowser; manifest.UseApplicationTrust = this.UseApplicationTrust; if (this.UseApplicationTrust && (this.SupportUrl != null)) { manifest.SupportUrl = this.SupportUrl; } if (this.UseApplicationTrust && (this.SuiteName != null)) { manifest.SuiteName = this.SuiteName; } if (this.UseApplicationTrust && (this.ErrorReportUrl != null)) { manifest.ErrorReportUrl = this.ErrorReportUrl; } return true; }
private bool AddIsolatedComReferences(ApplicationManifest manifest) { int tickCount = Environment.TickCount; bool flag = true; if (this.IsolatedComReferences != null) { foreach (ITaskItem item in this.IsolatedComReferences) { string metadata = item.GetMetadata("Name"); if (string.IsNullOrEmpty(metadata)) { metadata = Path.GetFileName(item.ItemSpec); } if (!base.AddFileFromItem(item).ImportComComponent(item.ItemSpec, manifest.OutputMessages, metadata)) { flag = false; } } } Util.WriteLog(string.Format(CultureInfo.CurrentCulture, "GenerateApplicationManifest.AddIsolatedComReferences t={0}", new object[] { Environment.TickCount - tickCount })); return flag; }