Exemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            PrepareFileFullPaths();

            // If a project file is specified, use MSBuild to build the package zip file.
            if (!string.IsNullOrEmpty(ProjectFile))
            {
                WriteVerbose(string.Format(Resources.StartBuildingProjectTemplate, fullProjectFile));
                fullPackage = WebsitesClient.BuildWebProject(fullProjectFile, configuration, Path.Combine(CurrentPath(), "build.log"));
                WriteVerbose(string.Format(Resources.CompleteBuildingProjectTemplate, fullProjectFile));
            }

            // Resolve the full path of the package file or folder when the "Package" parameter set is used.
            fullPackage = string.IsNullOrEmpty(fullPackage) ? this.TryResolvePath(Package) : fullPackage;
            WriteVerbose(string.Format(Resources.StartPublishingProjectTemplate, fullPackage));

            fullSetParametersFile = string.IsNullOrEmpty(fullSetParametersFile) ? this.TryResolvePath(SetParametersFile) : fullSetParametersFile;

            // Convert dynamic parameters to a connection string hash table.
            var connectionStrings = ConnectionString;

            if (connectionStrings == null)
            {
                connectionStrings = new Hashtable();
                if (dynamicParameters != null)
                {
                    foreach (var dp in dynamicParameters)
                    {
                        if (MyInvocation.BoundParameters.ContainsKey(dp.Key))
                        {
                            connectionStrings[dp.Value.Name.ToString()] = dp.Value.Value.ToString();
                        }
                    }
                }
            }

            try
            {
                // Publish the package.
                WebsitesClient.PublishWebProject(Name, Slot, fullPackage, fullSetParametersFile, connectionStrings, SkipAppData.IsPresent, DoNotDelete.IsPresent);
                WriteVerbose(string.Format(Resources.CompletePublishingProjectTemplate, fullPackage));
            }
            catch (Exception)
            {
                WriteVerbose(string.Format(Resources.FailPublishingProjectTemplate, fullPackage));
                throw;
            }
        }
        public override void ExecuteCmdlet()
        {
            PrepareFileFullPaths();

            // If a project file is specified, use MSBuild to build the package zip file.
            if (!string.IsNullOrEmpty(ProjectFile))
            {
                WriteVerbose(string.Format(Resources.StartBuildingProjectTemplate, fullProjectFile));
                fullPackage = WebsitesClient.BuildWebProject(fullProjectFile, configuration, Path.Combine(CurrentPath(), "build.log"));
                WriteVerbose(string.Format(Resources.CompleteBuildingProjectTemplate, fullProjectFile));
            }

            // Resolve the full path of the package file or folder when the "Package" parameter set is used.
            fullPackage = string.IsNullOrEmpty(fullPackage) ? this.TryResolvePath(Package) : fullPackage;
            WriteVerbose(string.Format(Resources.StartPublishingProjectTemplate, fullPackage));

            fullSetParametersFile = string.IsNullOrEmpty(fullSetParametersFile) ? this.TryResolvePath(SetParametersFile) : fullSetParametersFile;

            // Convert dynamic parameters to a connection string hash table.
            var connectionStrings = ConnectionString;

            if (connectionStrings == null)
            {
                connectionStrings = new Hashtable();
                if (dynamicParameters != null)
                {
                    foreach (var dp in dynamicParameters)
                    {
                        if (MyInvocation.BoundParameters.ContainsKey(dp.Key))
                        {
                            connectionStrings[dp.Value.Name.ToString()] = dp.Value.Value.ToString();
                        }
                    }
                }
            }

            if (!File.Exists(fullSetParametersFile))
            {
                if (File.Exists(Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile)))
                {
                    WriteVerbose("Setting path for Parameters file to local one to package: " + Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile));
                    fullSetParametersFile = Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile);
                }
            }

            // If tokens are passed in, update the parameters file if there is one
            if (!string.IsNullOrEmpty(Tokens) && !string.IsNullOrEmpty(fullSetParametersFile))
            {
                // Convert tokens string to hashtable
                string[] tokenSplit = Tokens.Split(';');

                WriteVerbose(string.Format("Replacing tokens in {0}", fullSetParametersFile));
                var fileContents = File.ReadAllText(fullSetParametersFile);

                foreach (string pair in tokenSplit)
                {
                    string[] data = pair.Split('=');
                    fileContents = fileContents.Replace(string.Format("__{0}__", data[0].Replace("\"", "")), data[1].Replace("\"", ""));
                }

                File.WriteAllText(fullSetParametersFile, fileContents);
            }

            try
            {
                // Publish the package.
                WebsitesClient.PublishWebProject(Name, Slot, fullPackage, fullSetParametersFile, connectionStrings, SkipAppData.IsPresent, DoNotDelete.IsPresent);
                WriteVerbose(string.Format(Resources.CompletePublishingProjectTemplate, fullPackage));
            }
            catch (Exception)
            {
                WriteVerbose(string.Format(Resources.FailPublishingProjectTemplate, fullPackage));
                throw;
            }
        }