Exemple #1
0
        public void ShouldUpdatePath()
        {
            const string websiteName = "AcmeOnline";

            variables.Set(SpecialVariables.Package.UpdateIisWebsite, true.ToString());
            variables.Set(SpecialVariables.Package.UpdateIisWebsiteName, websiteName);
            fileSystem.FileExists(Path.Combine(stagingDirectory, "Web.config")).Returns(true);
            iis.OverwriteHomeDirectory(websiteName, stagingDirectory, false).Returns(true);

            CreateConvention().Install(deployment);

            iis.Received().OverwriteHomeDirectory(websiteName, stagingDirectory, false);
        }
        public void Install(RunningDeployment deployment)
        {
            if (!deployment.Variables.GetFlag(SpecialVariables.Package.UpdateIisWebsite))
            {
                return;
            }

            var iisSiteName = deployment.Variables.Get(SpecialVariables.Package.UpdateIisWebsiteName);

            if (string.IsNullOrWhiteSpace(iisSiteName))
            {
                iisSiteName = deployment.Variables.Get(PackageVariables.PackageId);
            }

            var webRoot = GetRootMostDirectoryContainingWebConfig(deployment);

            if (webRoot == null)
            {
                throw new CommandException("A web.config file was not found, so no IIS configuration will be performed. To turn off this feature, use the 'Configure features' link in the deployment step configuration to disable IIS updates.");
            }

            // In situations where the IIS version cannot be correctly determined automatically,
            // this variable can be set to force IIS6 compatibility.
            var legacySupport = deployment.Variables.GetFlag(SpecialVariables.UseLegacyIisSupport);

            var updated = iis.OverwriteHomeDirectory(iisSiteName, webRoot, legacySupport);

            if (!updated)
            {
                throw new CommandException(
                          string.Format(
                              "Could not find an IIS website or virtual directory named '{0}' on the local machine. You need to create the site and/or virtual directory manually. To turn off this feature, use the 'Configure features' link in the deployment step configuration to disable IIS updates.",
                              iisSiteName));
            }

            Log.Info("The IIS website named '{0}' has had its path updated to: '{1}'", iisSiteName, webRoot);
        }