コード例 #1
0
        private void UpdateVersionWithAppendValue(XContainer nuSpec)
        {
            if (string.IsNullOrWhiteSpace(AppendToVersion))
            {
                return;
            }

            var package = nuSpec.ElementAnyNamespace("package");

            if (package == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));
            }

            var metadata = package.ElementAnyNamespace("metadata");

            if (metadata == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));
            }

            var version = metadata.ElementAnyNamespace("version");

            if (version == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <version> XML element. The NuSpec file appears to be invalid."));
            }

            version.Value  = string.Format("{0}-{1}", PackageVersion ?? version.Value, AppendToVersion.Trim());
            PackageVersion = version.Value;
        }
コード例 #2
0
        private void UpdatePackageIdWithAppendValue(XContainer nuSpec)
        {
            if (string.IsNullOrWhiteSpace(AppendToPackageId))
            {
                return;
            }

            var package = nuSpec.ElementAnyNamespace("package");

            if (package == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));
            }

            var metadata = package.ElementAnyNamespace("metadata");

            if (metadata == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));
            }

            var packageId = metadata.ElementAnyNamespace("id");

            if (packageId == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <id> XML element. The NuSpec file appears to be invalid."));
            }

            packageId.Value = string.Format("{0}.{1}", packageId.Value, AppendToPackageId.Trim());
        }
コード例 #3
0
        private static XElement GetVersionElementFromNuSpec(XContainer nuSpec)
        {
            var package = nuSpec.ElementAnyNamespace("package");

            if (package == null)
            {
                throw new Exception(
                          "The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
            }

            var metadata = package.ElementAnyNamespace("metadata");

            if (metadata == null)
            {
                throw new Exception(
                          "The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid.");
            }

            var version = metadata.ElementAnyNamespace("version");

            if (version == null)
            {
                throw new Exception(
                          "The NuSpec file does not contain a <version> XML element. The NuSpec file appears to be invalid.");
            }
            return(version);
        }
コード例 #4
0
        private void AddReleaseNotes(XContainer nuSpec)
        {
            if (string.IsNullOrWhiteSpace(ReleaseNotesFile))
            {
                return;
            }

            ReleaseNotesFile = fileSystem.GetFullPath(ReleaseNotesFile);

            if (!fileSystem.FileExists(ReleaseNotesFile))
            {
                LogWarning("OCT901", string.Format("The release notes file: {0} does not exist or could not be found. Release notes will not be added to the package.", ReleaseNotesFile));
                return;
            }

            LogMessage("Adding release notes from file: " + ReleaseNotesFile);

            var notes = fileSystem.ReadFile(ReleaseNotesFile);

            var package = nuSpec.ElementAnyNamespace("package");

            if (package == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));
            }

            var metadata = package.ElementAnyNamespace("metadata");

            if (metadata == null)
            {
                throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));
            }

            metadata.SetElementValue("releaseNotes", notes);
        }
コード例 #5
0
        private void AddFiles(XContainer nuSpec, IEnumerable <ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "")
        {
            var package = nuSpec.ElementAnyNamespace("package");

            if (package == null)
            {
                throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
            }

            var files = package.ElementAnyNamespace("files");

            if (files == null)
            {
                files = new XElement("files");
                package.Add(files);
            }

            foreach (var sourceFile in sourceFiles)
            {
                var destinationPath = sourceFile.ItemSpec;
                var link            = sourceFile.GetMetadata("Link");
                if (!string.IsNullOrWhiteSpace(link))
                {
                    destinationPath = link;
                }

                if (Path.IsPathRooted(destinationPath))
                {
                    destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
                }

                destinationPath = Path.Combine(targetDirectory, destinationPath);

                var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);

                LogMessage("Including file: " + sourceFile, MessageImportance.Normal);

                files.Add(new XElement("file",
                                       new XAttribute("src", Path.GetFullPath(sourceFilePath)),
                                       new XAttribute("target", destinationPath)
                                       ));
            }
        }
コード例 #6
0
        private void AddFiles(XContainer nuSpec, IEnumerable <ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "", string relativeTo = "")
        {
            var package = nuSpec.ElementAnyNamespace("package");

            if (package == null)
            {
                throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
            }

            var files = package.ElementAnyNamespace("files");

            if (files == null)
            {
                files = new XElement("files");
                package.Add(files);
            }

            if (!string.IsNullOrWhiteSpace(relativeTo) && Path.IsPathRooted(relativeTo))
            {
                relativeTo = fileSystem.GetPathRelativeTo(relativeTo, sourceBaseDirectory);
            }

            foreach (var sourceFile in sourceFiles)
            {
                var destinationPath = sourceFile.ItemSpec;
                var link            = sourceFile.GetMetadata("Link");
                if (!string.IsNullOrWhiteSpace(link))
                {
                    destinationPath = link;
                }

                if (!Path.IsPathRooted(destinationPath))
                {
                    destinationPath = fileSystem.GetFullPath(Path.Combine(sourceBaseDirectory, destinationPath));
                }

                if (Path.IsPathRooted(destinationPath))
                {
                    destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
                }

                if (!string.IsNullOrWhiteSpace(relativeTo))
                {
                    if (destinationPath.StartsWith(relativeTo, StringComparison.OrdinalIgnoreCase))
                    {
                        destinationPath = destinationPath.Substring(relativeTo.Length);
                    }
                }

                destinationPath = Path.Combine(targetDirectory, destinationPath);

                var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);

                sourceFilePath = Path.GetFullPath(sourceFilePath);

                if (!fileSystem.FileExists(sourceFilePath))
                {
                    LogMessage("The source file '" + sourceFilePath + "' does not exist, so it will not be included in the package", MessageImportance.High);
                    continue;
                }

                if (seenBefore.Contains(sourceFilePath))
                {
                    continue;
                }

                seenBefore.Add(sourceFilePath);

                var fileName = Path.GetFileName(destinationPath);
                if (string.Equals(fileName, "app.config", StringComparison.OrdinalIgnoreCase))
                {
                    if (fileSystem.FileExists(AppConfigFile))
                    {
                        var configFileName = Path.GetFileName(AppConfigFile);
                        destinationPath = Path.GetDirectoryName(destinationPath);
                        destinationPath = Path.Combine(destinationPath, configFileName);
                        files.Add(new XElement("file",
                                               new XAttribute("src", AppConfigFile),
                                               new XAttribute("target", destinationPath)
                                               ));

                        LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                    }
                    continue;
                }

                if (new[] { "Deploy.ps1", "DeployFailed.ps1", "PreDeploy.ps1", "PostDeploy.ps1" }.Any(f => string.Equals(f, fileName, StringComparison.OrdinalIgnoreCase)))
                {
                    var isNonRoot = destinationPath.Contains('\\') || destinationPath.Contains('/');
                    if (isNonRoot && !IgnoreNonRootScripts)
                    {
                        LogWarning("OCTNONROOT", "As of Octopus Deploy 2.4, PowerShell scripts that are not at the root of the package will not be executed. The script '" + destinationPath + "' lives in a subdirectory, so it will not be executed. If you want Octopus to execute this script, move it to the root of your project. If you don't want it to be executed, you can ignore this warning, or suppress it by setting the MSBuild property OctoPackIgnoreNonRootScripts=true");
                    }
                }

                var isTypeScript = string.Equals(Path.GetExtension(sourceFilePath), ".ts", StringComparison.OrdinalIgnoreCase);
                if (isTypeScript)
                {
                    if (IncludeTypeScriptSourceFiles)
                    {
                        files.Add(new XElement("file",
                                               new XAttribute("src", sourceFilePath),
                                               new XAttribute("target", destinationPath)
                                               ));

                        LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                    }

                    var changedSource      = Path.ChangeExtension(sourceFilePath, ".js");
                    var changedDestination = Path.ChangeExtension(destinationPath, ".js");
                    if (fileSystem.FileExists(changedSource))
                    {
                        files.Add(new XElement("file",
                                               new XAttribute("src", changedSource),
                                               new XAttribute("target", changedDestination)
                                               ));

                        LogMessage("Added file: " + changedDestination, MessageImportance.Normal);
                    }
                }
                else
                {
                    files.Add(new XElement("file",
                                           new XAttribute("src", sourceFilePath),
                                           new XAttribute("target", destinationPath)
                                           ));

                    LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                }
            }
        }
コード例 #7
0
        private void AddFiles(XContainer nuSpec, IEnumerable <ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "", string relativeTo = "")
        {
            var package = nuSpec.ElementAnyNamespace("package");

            if (package == null)
            {
                throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");
            }

            var files = package.ElementAnyNamespace("files");

            if (files == null)
            {
                files = new XElement("files");
                package.Add(files);
            }

            if (!string.IsNullOrWhiteSpace(relativeTo) && Path.IsPathRooted(relativeTo))
            {
                relativeTo = fileSystem.GetPathRelativeTo(relativeTo, sourceBaseDirectory);
            }

            foreach (var sourceFile in sourceFiles)
            {
                var destinationPath = sourceFile.ItemSpec;
                var link            = sourceFile.GetMetadata("Link");
                if (!string.IsNullOrWhiteSpace(link))
                {
                    destinationPath = link;
                }

                if (Path.IsPathRooted(destinationPath))
                {
                    destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
                }

                if (!string.IsNullOrWhiteSpace(relativeTo))
                {
                    if (destinationPath.StartsWith(relativeTo, StringComparison.OrdinalIgnoreCase))
                    {
                        destinationPath = destinationPath.Substring(relativeTo.Length);
                    }
                }

                destinationPath = Path.Combine(targetDirectory, destinationPath);

                var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);

                sourceFilePath = Path.GetFullPath(sourceFilePath);

                var isTypeScript = string.Equals(Path.GetExtension(sourceFilePath), ".ts", StringComparison.OrdinalIgnoreCase);
                if (isTypeScript)
                {
                    if (IncludeTypeScriptSourceFiles)
                    {
                        files.Add(new XElement("file",
                                               new XAttribute("src", sourceFilePath),
                                               new XAttribute("target", destinationPath)
                                               ));

                        LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                    }

                    var changedSource      = Path.ChangeExtension(sourceFilePath, ".js");
                    var changedDestination = Path.ChangeExtension(destinationPath, ".js");
                    if (fileSystem.FileExists(changedSource))
                    {
                        files.Add(new XElement("file",
                                               new XAttribute("src", changedSource),
                                               new XAttribute("target", changedDestination)
                                               ));

                        LogMessage("Added file: " + changedDestination, MessageImportance.Normal);
                    }
                }
                else
                {
                    files.Add(new XElement("file",
                                           new XAttribute("src", sourceFilePath),
                                           new XAttribute("target", destinationPath)
                                           ));

                    LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                }
            }
        }