private void OnSignAndSave(object sender, EventArgs e)
        {
            // Make sure the entered cert file exists
            if (File.Exists(m_PathTextBox.Text))
            {
                // Update hashes and size info for files
                m_AppManifest.ResolveFiles();
                m_AppManifest.UpdateFileInfo();

                // Write app manifest
                ManifestWriter.WriteManifest(m_AppManifest);

                // Sign app manifest
                ManifestHelper.SignManifest(m_AppManifest, m_PathTextBox.Text, m_PasswordTextBox.Text);
                ManifestHelper.UpdateDeployManifestAppReference(m_DeployManifest, m_AppManifest);

                // Write deploy manifest
                ManifestWriter.WriteManifest(m_DeployManifest);

                // sign deploy manifest
                ManifestHelper.SignManifest(m_DeployManifest, m_PathTextBox.Text, m_PasswordTextBox.Text);
                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                m_ErrorProvider.SetError(m_PathTextBox, "Invalid Path");
            }
        }
Пример #2
0
        /// <summary>
        /// Add required files from root directory.
        /// </summary>
        /// <param name="container">Container object.</param>
        public static void AddAssemblyReferences(Container container)
        {
            string root = container.FullPath;
            ApplicationManifest application = container.Application;

            // Cleaning references
            application.AssemblyReferences.Clear();
            application.FileReferences.Clear();

            // CommonLanguageRuntime (this reference came from VS exported application)
            var commonLanguageRuntime = new AssemblyReference()
            {
                AssemblyIdentity = new AssemblyIdentity("Microsoft.Windows.CommonLanguageRuntime", "4.0.30319.0"),
                IsPrerequisite   = true
            };

            application.AssemblyReferences.Add(commonLanguageRuntime);

            // Add all files references
            InternalAddAssemblyReferences(application, root, root);

            application.ResolveFiles();
            application.UpdateFileInfo(application.TargetFrameworkVersion);
        }
Пример #3
0
        internal static void Build(Project project)
        {
            var application = new ApplicationManifest
            {
                IsClickOnceManifest    = true,
                ReadOnly               = false,
                IconFile               = project.IconFile.Value,
                OSVersion              = project.OsVersion.Value,
                OSDescription          = project.OsDescription.Value,
                OSSupportUrl           = project.OsSupportUrl.Value,
                TargetFrameworkVersion = project.TargetFramework.Version,
                HostInBrowser          = project.LaunchMode.Value == LaunchMode.Browser,
                AssemblyIdentity       = new AssemblyIdentity
                {
                    Name    = Path.GetFileName(project.EntryPoint.Value),
                    Version = project.Version.Value,
                    Culture = project.Culture.Value,
                    ProcessorArchitecture = project.ProcessorArchitecture.Value.ToString().ToLowerInvariant()
                },
                UseApplicationTrust = project.UseApplicationTrust.Value,
                TrustInfo           = project.TrustInfo.Resolve()
            };

            if (project.UseApplicationTrust.Value)
            {
                application.Publisher      = project.Publisher.Value;
                application.SuiteName      = project.Suite.Value;
                application.Product        = project.Product.Value;
                application.SupportUrl     = project.SupportUrl.Value;
                application.ErrorReportUrl = project.ErrorUrl.Value;
                application.Description    = project.Description.Value;
            }

            application.AddEntryPoint(project);
            application.AddIconFile(project);
            application.AddGlob(project, project.Assemblies);
            application.AddGlob(project, project.DataFiles);
            application.AddGlob(project, project.Files);
            application.AddFileAssociations(project);

            application.ResolveFiles();
            application.UpdateFileInfo(project.TargetFramework.Version);

            Logger.Normal(Messages.Build_Process_Application);
            application.Validate();
            Logger.OutputMessages(application.OutputMessages, 1);

            if (!project.PackageMode.Value.HasFlag(PackageMode.Application))
            {
                return;
            }

            Directory.CreateDirectory(Path.GetDirectoryName(project.ApplicationManifestFile.RootedPath));
            ManifestWriter.WriteManifest(application, project.ApplicationManifestFile.RootedPath, project.TargetFramework.Version);
            var signed = Utilities.Sign(project.ApplicationManifestFile.RootedPath, project);

            Logger.Normal(Messages.Build_Process_Manifest, 1, 1, project.ApplicationManifestFile.RootedPath);
            if (signed)
            {
                Logger.Normal(Messages.Build_Process_Manifest_Signed, 1);
            }
            Logger.Normal();
        }
Пример #4
0
        private ApplicationManifest CreateApplicationManifest(string entryPoint, out string configFileName, out string entryPointFilePath)
        {
            entryPointFilePath = null;
            string frameworkVersion;

            if (string.IsNullOrEmpty(TargetFramework))
            {
                frameworkVersion = "3.5";
            }
            else
            {
                FrameworkName fn = new FrameworkName(TargetFramework);
                frameworkVersion = fn.Version.ToString();
            }
            ApplicationManifest manifest = new ApplicationManifest(frameworkVersion);

            manifest.IsClickOnceManifest = true;
            manifest.IconFile            = IconFile;
            configFileName = null;

            Dictionary <string, AssemblyIdentity> addedIdentities = new Dictionary <string, AssemblyIdentity>();
            string basePath = Path.GetFullPath(BasePath);

            foreach (var taskItem in Files.Where(MatchFilter))
            {
                string        filePath   = taskItem.GetMetadata("FullPath");
                string        targetPath = null;
                string        dir        = Path.GetDirectoryName(filePath);
                string        fileName   = Path.GetFileName(filePath);
                BaseReference reference  = null;
                if (!dir.Equals(basePath, StringComparison.InvariantCultureIgnoreCase) &&
                    dir.StartsWith(basePath, StringComparison.InvariantCultureIgnoreCase))
                {
                    int index = basePath.Length;
                    if (dir[index] == Path.DirectorySeparatorChar)
                    {
                        index++;
                    }

                    targetPath = Path.Combine(dir.Substring(index), fileName);
                }


                AssemblyIdentity identity = null;
                try
                {
                    identity = AssemblyIdentity.FromFile(filePath);
                    if (LinkAssembliesWithManifestAsFile && HasEmbeddedManifest(filePath))
                    {
                        identity = null;
                    }
                }
                catch (BadImageFormatException)
                {
                }

                if (identity != null)
                {
                    string identityFullName = identity.GetFullName(AssemblyIdentity.FullNameFlags.All);
                    if (addedIdentities.ContainsKey(identityFullName))
                    {
                        throw new DuplicateAssemblyReferenceException(identityFullName);
                    }
                    else
                    {
                        addedIdentities.Add(identityFullName, identity);
                    }

                    AssemblyReference asmRef = new AssemblyReference(fileName);
                    reference = asmRef;
                    asmRef.AssemblyIdentity = identity;
                    manifest.AssemblyReferences.Add(asmRef);
                    if (manifest.EntryPoint == null &&
                        (string.IsNullOrEmpty(entryPoint) || string.Equals(entryPoint, fileName, StringComparison.InvariantCultureIgnoreCase)) &&
                        Path.GetExtension(fileName).Equals(".exe", StringComparison.InvariantCultureIgnoreCase))
                    {
                        configFileName     = SetEntryPointAndConfig(manifest, filePath, asmRef);
                        entryPointFilePath = filePath;
                    }
                }
                else
                {
                    FileReference fileRef = new FileReference(fileName);
                    reference = fileRef;
                    manifest.FileReferences.Add(fileRef);
                }

                Log.LogMessage(MessageImportance.Low, "TargetPath for {0}: {1}", fileName, targetPath);
                reference.TargetPath = targetPath;
            }

            List <string> searchPaths = new List <string>();

            searchPaths.Add(BasePath);
            if (ConfigFile != null)
            {
                searchPaths.Add(Path.GetDirectoryName(ConfigFile.ItemSpec));
            }
            manifest.ResolveFiles(searchPaths.ToArray());
            manifest.UpdateFileInfo();

            TrustInfo trust = new TrustInfo();

            trust.IsFullTrust  = true;
            manifest.TrustInfo = trust;
            if (manifest.EntryPoint == null)
            {
                Log.LogError("Cannot determine EntryPoint. EntryPoint property = '{0}'", entryPoint ?? string.Empty);
            }

            return(manifest);
        }
Пример #5
0
        /// <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);
            }
        }