示例#1
0
        public static InstallationSpecification FromAssembly(Assembly targetAssembly)
        {
            // var specType = typeof (InstallationSpecification);
            // var spec = targetAssembly.GetTypes().FirstOrDefault(x => specType.IsAssignableFrom(x.BaseType));

            var isUserMode        = targetAssembly.Attribute <InstallUserModeAttribute>();
            var identityAttribute = targetAssembly.Attribute <InstallerIdentityAttribute>();
            var titleAttribute    = targetAssembly.Attribute <AssemblyTitleAttribute>();
            var productAttribute  = targetAssembly.Attribute <AssemblyProductAttribute>();

            var location_ = string.IsNullOrEmpty(targetAssembly.Location) ? Assembly.GetEntryAssembly().Location : targetAssembly.Location;

            var fileName = Path.GetFileNameWithoutExtension(location_);

            var identity = string.Empty;

            if (string.IsNullOrEmpty(identity) && identityAttribute != null)
            {
                identity = identityAttribute.Identity;
            }

            if (string.IsNullOrEmpty(identity) && productAttribute != null)
            {
                identity = productAttribute.Product;
            }

            if (string.IsNullOrEmpty(identity) && titleAttribute != null)
            {
                identity = titleAttribute.Title;
            }

            if (string.IsNullOrEmpty(identity))
            {
                identity = fileName;
            }

            var container    = GetFileContainer(targetAssembly);
            var specAssembly = GetAssemblyFileId(targetAssembly, container);
            var spec         = new InstallationSpecification
            {
                IsUserMode                = isUserMode == null ? true : isUserMode.IsUserMode,
                Identity                  = identity,
                FilesToInstall            = container,
                SpecAssembly              = specAssembly,
                Publisher                 = targetAssembly.Attribute <AssemblyCompanyAttribute>().Company,
                DisplayVersion            = targetAssembly.Attribute <AssemblyFileVersionAttribute>().Version,
                AssembliesForInstallUtils = GetAssembliesForInstallUtils(container, targetAssembly).ToArray(),
            };

            return(spec);
        }
 public InstallationProcessor(InstallationSpecification spec)
 {
     _spec = spec;
 }