/// <summary> /// Set the application's trust information /// </summary> /// <param name="manifest">ApplicationManifest object</param> /// <param name="trustLevel">Trust level</param> private static void SetTrustLevel(ApplicationManifest manifest, Command.TrustLevels trustLevel) { if (trustLevel != Command.TrustLevels.None) { TrustInfo ti = new Microsoft.Build.Tasks.Deployment.ManifestUtilities.TrustInfo(); manifest.TrustInfo = ti; if (trustLevel == Command.TrustLevels.FullTrust) { ti.IsFullTrust = true; } else { ti.PermissionSet = SecurityUtilities.ComputeZonePermissionSet(trustLevel.ToString(), null, null); ti.IsFullTrust = false; } } }
/// <summary> /// Generates Application manifest /// </summary> /// <param name="filesToIgnore">List of files to ignore</param> /// <param name="nameArgument">Product name</param> /// <param name="appName">Application name</param> /// <param name="version">Version</param> /// <param name="processor">Processor type</param> /// <param name="trustLevel">Trust level</param> /// <param name="fromDirectory">Directory from which to harvest files.</param> /// <param name="iconFile">Icon file</param> /// <param name="useApplicationManifestForTrustInfo">Specifies if Application manifest is used for trust info</param> /// <param name="publisherName">Publisher name</param> /// <param name="supportUrl">Support URL</param> /// <param name="targetFrameworkVersion">Target Framework version</param> /// <returns>ApplicationManifest object</returns> public static ApplicationManifest GenerateApplicationManifest(List <string> filesToIgnore, string nameArgument, string appName, Version version, Processors processor, Command.TrustLevels trustLevel, string fromDirectory, string iconFile, TriStateBool useApplicationManifestForTrustInfo, string publisherName, string supportUrl, string targetFrameworkVersion) { ApplicationManifest manifest = new ApplicationManifest(); // Default to full trust for manifest generation if (trustLevel == Command.TrustLevels.None) { trustLevel = Command.TrustLevels.FullTrust; } // Use a default name for generated manifests if (appName == null) { appName = Application.Resources.GetString("DefaultAppName"); } // Use a default version for generated manifests if (version == null) { version = defaultVersion; } // Use a default processor for generated manifests if (processor == Processors.Undefined) { processor = Processors.msil; } UpdateApplicationManifest(filesToIgnore, manifest, nameArgument, appName, version, processor, trustLevel, fromDirectory, iconFile, useApplicationManifestForTrustInfo, publisherName, supportUrl, targetFrameworkVersion); return(manifest); }
/// <summary> /// Updates Application manifest /// </summary> /// <param name="filesToIgnore">List of files to ignore</param> /// <param name="manifest">ApplicationManifest object</param> /// <param name="nameArgument">Product name</param> /// <param name="appName">Application name</param> /// <param name="version">Version</param> /// <param name="processor">Processor type</param> /// <param name="trustLevel">Trust level</param> /// <param name="fromDirectory">Directory from where to harvest the files.</param> /// <param name="iconFile">Icon file</param> /// <param name="useApplicationManifestForTrustInfo">Specifies if ApplicationManifest should be used for trust info</param> /// <param name="publisherName">Publisher name</param> /// <param name="supportUrl">Support URL</param> /// <param name="targetFrameworkVersion">Target Framework version</param> public static void UpdateApplicationManifest(List <string> filesToIgnore, ApplicationManifest manifest, string nameArgument, string appName, Version version, Processors processor, Command.TrustLevels trustLevel, string fromDirectory, string iconFile, TriStateBool useApplicationManifestForTrustInfo, string publisherName, string supportUrl, string targetFrameworkVersion) { if (appName != null) { manifest.AssemblyIdentity.Name = appName; } else if (!string.IsNullOrEmpty(manifest.AssemblyIdentity.Name)) { appName = manifest.AssemblyIdentity.Name; } if (version != null) { manifest.AssemblyIdentity.Version = version.ToString(); } if (processor != Processors.Undefined) { manifest.AssemblyIdentity.ProcessorArchitecture = processor.ToString(); } // Culture is not supported by command-line arguments, but it gets defaulted if not already present in the manifest if ((manifest.AssemblyIdentity.Culture == null) || (manifest.AssemblyIdentity.Culture.Length == 0)) { manifest.AssemblyIdentity.Culture = defaultCulture; } #if RUNTIME_TYPE_NETCORE // TrustInfo is always Full-trust on .NET (Core) if (manifest.TrustInfo == null) { // TrustInfo object is initialized as Full-trust for all apps running on .NET (Core) manifest.TrustInfo = new Microsoft.Build.Tasks.Deployment.ManifestUtilities.TrustInfo(); } #else if (trustLevel != Command.TrustLevels.None) { SetTrustLevel(manifest, trustLevel); } #endif if (iconFile != null) { manifest.IconFile = iconFile; } if (useApplicationManifestForTrustInfo == TriStateBool.True) { manifest.UseApplicationTrust = true; if (!string.IsNullOrEmpty(nameArgument)) { manifest.Product = nameArgument; } else if (appName != null) { if (appName.ToLower().EndsWith(".exe")) { // remove the trailing .exe extension manifest.Product = appName.Substring(0, appName.Length - ".exe".Length); } else { manifest.Product = appName; } } if (!string.IsNullOrEmpty(publisherName)) { manifest.Publisher = publisherName; } else { // Get the default publisher name manifest.Publisher = Utilities.Misc.GetRegisteredOrganization(); } if (!string.IsNullOrEmpty(supportUrl)) { manifest.SupportUrl = supportUrl; } } if (fromDirectory != null) { Utilities.AppMan.AddReferences(manifest, false, fromDirectory, filesToIgnore, new AppMan.LockedFileReporter(LockedFileReporter), null, null, null, new ArrayList()); // Update file sizes and hashes for the new references. // This uses Manifest methods rather than Utilities.AppMan.UpdateReferenceInfo // because in this case we want to report any missing files in the manifest. manifest.OutputMessages.Clear(); manifest.ResolveFiles(); manifest.UpdateFileInfo(targetFrameworkVersion); // Set entry point and config files Utilities.AppMan.SetSpecialFiles(manifest); } else { // -FromDirectory was not specified, but try to update // existing references if possible. Utilities.AppMan.UpdateReferenceInfo(manifest, "", null, null, targetFrameworkVersion); } }