Exemplo n.º 1
0
        public static int AddPackage(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
        {
            PrintInfo();
            Logging.Configure();
            Telemetry.AddPackage();
            ProjectModelTasks.Initialize();

            var packageId      = args.ElementAt(0);
            var packageVersion =
                (EnvironmentInfo.GetParameter <string>("version") ??
                 args.ElementAtOrDefault(1) ??
                 NuGetPackageResolver.GetLatestPackageVersion(packageId, includePrereleases: false).GetAwaiter().GetResult() ??
                 NuGetPackageResolver.GetGlobalInstalledPackage(packageId, version: null, packagesConfigFile: null)?.Version.ToString())
                .NotNull("packageVersion != null");

            var configuration    = GetConfiguration(buildScript, evaluate: true);
            var buildProjectFile = configuration[BUILD_PROJECT_FILE];

            Host.Information($"Installing {packageId}/{packageVersion} to {buildProjectFile} ...");
            AddOrReplacePackage(packageId, packageVersion, PACKAGE_TYPE_DOWNLOAD, buildProjectFile);
            DotNetTasks.DotNet($"restore {buildProjectFile}");

            var installedPackage = NuGetPackageResolver.GetGlobalInstalledPackage(packageId, packageVersion, packagesConfigFile: null)
                                   .NotNull("installedPackage != null");
            var hasToolsDirectory = installedPackage.Directory.GlobDirectories("tools").Any();

            if (!hasToolsDirectory)
            {
                AddOrReplacePackage(packageId, packageVersion, PACKAGE_TYPE_REFERENCE, buildProjectFile);
            }

            Host.Information($"Done installing {packageId}/{packageVersion} to {buildProjectFile}");
            return(0);
        }
Exemplo n.º 2
0
        public static int Setup(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
        {
            PrintInfo();
            Logging.Configure();
            Telemetry.SetupBuild();

            AnsiConsole.WriteLine();
            AnsiConsole.MarkupLine("[bold]Let's setup a new build![/]");
            AnsiConsole.WriteLine();

            #region Basic

            var nukeLatestReleaseVersion    = NuGetPackageResolver.GetLatestPackageVersion(NukeCommonPackageId, includePrereleases: false);
            var nukeLatestPrereleaseVersion = NuGetPackageResolver.GetLatestPackageVersion(NukeCommonPackageId, includePrereleases: true);
            var nukeLatestLocalVersion      = NuGetPackageResolver.GetGlobalInstalledPackage(NukeCommonPackageId, version: null, packagesConfigFile: null)
                                              ?.Version.ToString();

            if (rootDirectory == null)
            {
                var rootDirectoryItems = new[] { ".git", ".svn" };
                rootDirectory = (AbsolutePath)FileSystemTasks.FindParentDirectory(
                    WorkingDirectory,
                    x => rootDirectoryItems.Any(y => x.GetFileSystemInfos(y, SearchOption.TopDirectoryOnly).Any()));
            }

            if (rootDirectory == null)
            {
                Host.Warning("Could not find root directory. Falling back to working directory ...");
                rootDirectory = WorkingDirectory;
            }
            ShowInput("deciduous_tree", "Root directory", rootDirectory);

            var targetPlatform = !GetParameter <bool>("boot")
                ? PLATFORM_NETCORE
                : PromptForChoice("What runtime should be used?",
                                  (PLATFORM_NETCORE, ".NET Core SDK"),
                                  (PLATFORM_NETFX, ".NET Framework/Mono"));

            var targetFramework = targetPlatform == PLATFORM_NETFX
                ? FRAMEWORK_NETFX
                : FRAMEWORK_NETCORE;

            var projectFormat = targetPlatform == PLATFORM_NETCORE
                ? FORMAT_SDK
                : PromptForChoice("What project format should be used?",
                                  (FORMAT_SDK, "SDK-based Format: requires .NET Core SDK"),
                                  (FORMAT_LEGACY, "Legacy Format: supported by all MSBuild/Mono versions"));

            ShowInput("nut_and_bolt", "Build runtime", $"{(targetPlatform == PLATFORM_NETCORE ? ".NET" : ".NET Framework")} ({targetFramework})");

            var buildProjectName = PromptForInput("How should the project be named?", "_build");
            ClearPreviousLine();
            ShowInput("bookmark", "Build project name", buildProjectName);

            var buildProjectRelativeDirectory = PromptForInput("Where should the project be located?", "./build");
            ClearPreviousLine();
            ShowInput("round_pushpin", "Build project location", buildProjectRelativeDirectory);

            var nukeVersion = PromptForChoice("Which Nuke.Common version should be used?",
                                              new[]
Exemplo n.º 3
0
        public void TestGetGlobalInstalledPackage()
        {
            var result = NuGetPackageResolver.GetGlobalInstalledPackage("xunit.runner.console", version: null, packagesConfigFile: null);

            result.Should().NotBeNull();
            result.Id.Should().Be("xunit.runner.console");
            result.FileName.Should().EndWith("nupkg");
            result.Version.OriginalVersion.Should().Be(XunitConsolePackageVersion);
        }
Exemplo n.º 4
0
        private static void Setup([CanBeNull] string rootDirectory, string[] args)
        {
            #region Basic

            var nukeLatestLocalVersion      = NuGetPackageResolver.GetGlobalInstalledPackage("Nuke.Common", version: null)?.Version.ToString();
            var nukeLatestReleaseVersion    = NuGetPackageResolver.GetLatestPackageVersion("Nuke.Common", includePrereleases: false);
            var nukeLatestPrereleaseVersion = NuGetPackageResolver.GetLatestPackageVersion("Nuke.Common", includePrereleases: true);

            if (rootDirectory == null)
            {
                var rootDirectoryItems = new[] { ".git", ".svn" };
                rootDirectory = FileSystemTasks.FindParentDirectory(
                    EnvironmentInfo.WorkingDirectory,
                    x => rootDirectoryItems.Any(y => x.GetFileSystemInfos(y, SearchOption.TopDirectoryOnly).Any()));
            }

            if (rootDirectory == null)
            {
                Logger.Warn("Could not find root directory. Falling back to working directory.");
                rootDirectory = EnvironmentInfo.WorkingDirectory;
            }

            var solutionFile = ConsoleHelper.PromptForChoice(
                "Which solution should be the default?",
                options: new DirectoryInfo(rootDirectory)
                .EnumerateFiles("*", SearchOption.AllDirectories)
                .Where(x => x.FullName.EndsWithOrdinalIgnoreCase(".sln"))
                .OrderByDescending(x => x.FullName)
                .Select(x => (x, GetRelativePath(rootDirectory, x.FullName)))
                .Concat((null, "None")).ToArray())?.FullName;
            var solutionDirectory = solutionFile != null?Path.GetDirectoryName(solutionFile) : null;

            var targetPlatform = ConsoleHelper.PromptForChoice("How should the build project be bootstrapped?",
                                                               (PLATFORM_NETCORE, ".NET Core SDK"),
                                                               (PLATFORM_NETFX, ".NET Framework/Mono"));

            var targetFramework = targetPlatform == PLATFORM_NETFX
                ? FRAMEWORK_NET461
                : ConsoleHelper.PromptForChoice("What target framework should be used?",
                                                (FRAMEWORK_NETCOREAPP2, FRAMEWORK_NETCOREAPP2),
                                                (FRAMEWORK_NET461, FRAMEWORK_NET461));

            var projectFormat = targetPlatform == PLATFORM_NETCORE
                ? FORMAT_SDK
                : ConsoleHelper.PromptForChoice("What format should the build project use?",
                                                (FORMAT_SDK, "SDK-based Format: requires .NET Core SDK"),
                                                (FORMAT_LEGACY, "Legacy Format: supported by all MSBuild/Mono versions"));

            var nukeVersion = ConsoleHelper.PromptForChoice("Which NUKE version should be used?",
                                                            new[]
Exemplo n.º 5
0
        private static int Setup(string[] args, [CanBeNull] string rootDirectory, [CanBeNull] string buildScript)
        {
            PrintInfo();

            #region Basic

            var nukeLatestReleaseVersion    = NuGetPackageResolver.GetLatestPackageVersion("Nuke.Common", includePrereleases: false);
            var nukeLatestPrereleaseVersion = NuGetPackageResolver.GetLatestPackageVersion("Nuke.Common", includePrereleases: true);
            var nukeLatestLocalVersion      = NuGetPackageResolver.GetGlobalInstalledPackage("Nuke.Common", version: null, packagesConfigFile: null)
                                              ?.Version.ToString();

            if (rootDirectory == null)
            {
                var rootDirectoryItems = new[] { ".git", ".svn" };
                rootDirectory = FileSystemTasks.FindParentDirectory(
                    WorkingDirectory,
                    x => rootDirectoryItems.Any(y => x.GetFileSystemInfos(y, SearchOption.TopDirectoryOnly).Any()));
            }

            if (rootDirectory == null)
            {
                Logger.Warn("Could not find root directory. Falling back to working directory.");
                rootDirectory = WorkingDirectory;
            }

            var buildProjectName   = PromptForInput("How should the build project be named?", "_build");
            var buildDirectoryName = PromptForInput("Where should the build project be located?", "./build");

            var targetPlatform = !GetParameter <bool>("boot")
                ? PLATFORM_NETCORE
                : PromptForChoice("What bootstrapping method should be used?",
                                  (PLATFORM_NETCORE, ".NET Core SDK"),
                                  (PLATFORM_NETFX, ".NET Framework/Mono"));

            var targetFramework = targetPlatform == PLATFORM_NETFX
                ? FRAMEWORK_NETFX
                : FRAMEWORK_NETCORE;

            var projectFormat = targetPlatform == PLATFORM_NETCORE
                ? FORMAT_SDK
                : PromptForChoice("What project format should be used?",
                                  (FORMAT_SDK, "SDK-based Format: requires .NET Core SDK"),
                                  (FORMAT_LEGACY, "Legacy Format: supported by all MSBuild/Mono versions"));

            var nukeVersion = PromptForChoice("Which NUKE version should be used?",
                                              new[]
Exemplo n.º 6
0
        private static int Fix(string[] args, [CanBeNull] string rootDirectory, [CanBeNull] string buildScript)
        {
            PrintInfo();

            if (rootDirectory == null)
            {
                return(0);
            }

            var missingPackageFile = Constants.GetMissingPackageFile((AbsolutePath)rootDirectory);

            if (!File.Exists(missingPackageFile))
            {
                return(0);
            }

            Logger.Info("During last execution a package was found to be missing.");

            var missingPackageContents = File.ReadAllLines(missingPackageFile);
            var buildProjectFile       = missingPackageContents.FirstOrDefault();

            ControlFlow.Assert(File.Exists(buildProjectFile), $"File.Exists({buildProjectFile})");

            var packages = missingPackageContents
                           .Skip(1)
                           .Select(x => x.Split("@", StringSplitOptions.RemoveEmptyEntries))
                           .ForEachLazy(x => ControlFlow.Assert(x.Length == 2, "x.Length == 2"))
                           .Select(x => (packageName: x[0], version: x[1])).ToList();

            ControlFlow.Assert(packages.Count > 0, "packages.Count > 0");

            var(selectedPackageId, selectedPackageVersion) = packages.Count == 1
                ? packages.Single()
                : PromptForChoice("Which package should be added?",
                                  packages.Select(x => (x, x.packageName)).ToArray());

            if (selectedPackageVersion == ToolPathResolver.MissingPackageDefaultVersion)
            {
                var latestReleaseVersion    = NuGetPackageResolver.GetLatestPackageVersion(selectedPackageId, includePrereleases: false);
                var latestPrereleaseVersion = NuGetPackageResolver.GetLatestPackageVersion(selectedPackageId, includePrereleases: true);
                var latestLocalVersion      = NuGetPackageResolver.GetGlobalInstalledPackage(selectedPackageId, version: null, packagesConfigFile: null)
                                              ?.Version.ToString();

                var packageVersions = new[]