Beispiel #1
0
    /// <summary>
    /// Get the absolute path to a given project's compile output directory.
    /// </summary>
    /// <param name="name">The name of the project.</param>
    /// <returns>The full, absolute path to the directory specified by a
    /// project's "OutputPath" property.</returns>
    public AbsolutePath GetOutputPath(string name)
    {
        Project n = Solution.GetProject(name);

        // The OutputPath property has a different value depending on the active
        // build configuration, so it's necessary to take that into account.
        Microsoft.Build.Evaluation.Project parsed = ProjectModelTasks.ParseProject(n, Configuration);

        return(n.Directory / parsed.GetPropertyValue("OutputPath"));
    }
Beispiel #2
0
        public static void Update(string projectFile)
        {
            var buildProject = ProjectModelTasks.ParseProject(projectFile).NotNull();

            UpdateTargetFramework(buildProject);
            UpdateNukeCommonPackage(buildProject, out var previousPackageVersion);

            if (previousPackageVersion.MinVersion >= NuGetVersion.Parse("0.23.5"))
            {
                RemoveLegacyFileIncludes(buildProject);
            }

            buildProject.Save();
        }
Beispiel #3
0
        private static int?CheckAwareness()
        {
            string GetCookieFile(string name, int version)
            => Constants.GlobalNukeDirectory / "telemetry-awareness" / $"v{version}" / name;

            // Check for calls from Nuke.GlobalTool and custom global tools
            if (SuppressErrors(() => NukeBuild.BuildProjectFile, logWarning: false) == null)
            {
                var cookieName = Assembly.GetEntryAssembly().NotNull().GetName().Name;
                var cookieFile = GetCookieFile(cookieName, CurrentVersion);
                if (!File.Exists(cookieFile))
                {
                    PrintDisclosure($"create awareness cookie for {cookieName.SingleQuote()}");
                    FileSystemTasks.Touch(cookieFile);
                }

                return(CurrentVersion);
            }

            var project  = ProjectModelTasks.ParseProject(NukeBuild.BuildProjectFile);
            var property = project.Properties.SingleOrDefault(x => x.Name.EqualsOrdinalIgnoreCase(VersionPropertyName));

            if (property?.EvaluatedValue != CurrentVersion.ToString())
            {
                if (NukeBuild.IsServerBuild)
                {
                    PrintDisclosure(action: null);
                    return(null);
                }

                PrintDisclosure($"set the {VersionPropertyName.SingleQuote()} property");
                project.SetProperty(VersionPropertyName, CurrentVersion.ToString());
                project.Save();
            }

            for (var version = CurrentVersion; version > 0; version--)
            {
                if (File.Exists(GetCookieFile("Nuke.GlobalTool", version)))
                {
                    return(version);
                }
            }

            return(NukeBuild.IsServerBuild ? CurrentVersion : null);
        }
Beispiel #4
0
        private static void AddOrReplacePackage(string packageId, string packageVersion, string packageType, string buildProjectFile)
        {
            var buildProject = ProjectModelTasks.ParseProject(buildProjectFile).NotNull();

            var previousPackage = buildProject.Items.SingleOrDefault(x => x.EvaluatedInclude == packageId);

            if (previousPackage != null)
            {
                buildProject.RemoveItem(previousPackage);
            }

            var packageDownloadItem = buildProject.AddItem(packageType, packageId).Single();

            packageDownloadItem.Xml.AddMetadata(
                "Version",
                packageType == PACKAGE_TYPE_REFERENCE ? packageVersion : $"[{packageVersion}]",
                expressAsAttribute: true);
            buildProject.Save();
        }
Beispiel #5
0
        public static int Update(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript)
        {
            Assert(rootDirectory != null, "rootDirectory != null");

            if (buildScript != null)
            {
                if (UserConfirms("Update build scripts?"))
                {
                    UpdateBuildScripts(rootDirectory, buildScript);
                }

                if (UserConfirms("Update build project?"))
                {
                    var configuration = GetConfiguration(buildScript, evaluate: true);
                    var buildProject  = ProjectModelTasks.ParseProject(configuration[BUILD_PROJECT_FILE]).NotNull();

                    UpdateTargetFramework(buildProject);
                    UpdateNukeCommonPackage(buildProject, out var previousPackageVersion);

                    if (previousPackageVersion.MinVersion >= NuGetVersion.Parse("0.23.5"))
                    {
                        RemoveLegacyFileIncludes(buildProject);
                    }

                    buildProject.Save();
                }
            }

            if (UserConfirms("Update configuration file?"))
            {
                UpdateConfigurationFile(rootDirectory);
            }

            if (UserConfirms("Update global.json?"))
            {
                UpdateGlobalJsonFile(rootDirectory);
            }

            return(0);
        }