예제 #1
0
        public void Execute()
        {
            var sbsInstallHome = ConfigurationManager.AppSettings["SBS_INSTALL_HOME"];

            if (sbsInstallHome == null)
            {
                throw new NullReferenceException("The location of the SBSInstall.exe directory must be set in the config.");
            }

            if (BuildDirectory == null)
            {
                throw new NullReferenceException("Build directory must be set.");
            }

            BuildDirectory.Refresh();
            if (!BuildDirectory.Exists)
            {
                throw new ArgumentException(string.Format("Build directory {0} does not exist.",
                                                          BuildDirectory.FullName));
            }

            if (Target == null || Target.Trim().Length == 0)
            {
                throw new NullReferenceException("Target must be set.");
            }

            if (Version == null)
            {
                throw new NullReferenceException("Version must be set.");
            }

            if (Archive == null)
            {
                throw new NullReferenceException("Archive location must be set.");
            }

            if (Type == null)
            {
                throw new Exception("Installation must be set.");
            }

            if ((Type == InstallType.Service || Type == InstallType.WebService) &&
                string.IsNullOrEmpty(ServiceName))
            {
                throw new Exception("Sevice name must be specified for Service and WebService installations.");
            }

            var projectName = Path.GetFileNameWithoutExtension(ProjectFile.FullName);
            var zipDir      = BuildDirectory.FullName + "\\_PublishedWebsites\\" + projectName;

            if (!Directory.Exists(zipDir))
            {
                zipDir = BuildDirectory.FullName;
            }

            var paths = Directory.GetFiles(zipDir, "*.*", SearchOption.AllDirectories);

            if (paths.Length == 0)
            {
                Log.Warn(string.Format("No files found to zip in directory {0}. ", zipDir));
                return;
            }

            var zipFileName = string.Format("{0}\\Setup-{1}-{2}-{3}.zip", Archive.Uri, AssemblyName, Target, Version);

            var zip = new Zip();

            zip.ExeXmlConfig = ((SfxConfig)System.Configuration.ConfigurationManager.GetSection("SfxConfig")).ExeXmlConfig;
            zip.UnlockComponent("SHUTTEZIP_sYpChNabpHrd");
            zip.NewZip(zipFileName);

            zip.PathPrefix = "application/";
            zip.AppendFiles(zipDir, true);

            zip.PathPrefix = "installer/";
            zip.AppendFiles(sbsInstallHome, true);

            zip.AutoTemp = true;
            zip.AutoRun  = "installer/SBSInstaller.exe";
            var args = "-t {0} -a {1} -d application";

            if (!string.IsNullOrEmpty(ServiceName))
            {
                args += " -s \"{2}\"";
            }
            if (!string.IsNullOrEmpty(WebsiteName))
            {
                args += " -w \"{3}\"";
            }
            if (!string.IsNullOrEmpty(AppPoolName))
            {
                args += " -p \"{4}\"";
            }
            zip.AutoRunParams = string.Format(args, Type, AssemblyName, ServiceName, WebsiteName, AppPoolName);

            zip.ExeTitle = string.Format("Self Extracting Installation for {0} {1}", AssemblyName, Type);

            var fileName       = string.Format("Setup--{0}-{1}.exe", Target, Version);
            var zipExeFileName = Archive.Archive(zip, Target, fileName);

            ArchiveZipExeFile = zipExeFileName;

            Log.Info(string.Format("Compression of directory {0} to installation file {1} complete.", zipDir, zipExeFileName));
        }