static Telemetry() { var optoutParameter = EnvironmentInfo.GetParameter <string>(OptOutEnvironmentKey) ?? string.Empty; if (optoutParameter == "1" || optoutParameter.EqualsOrdinalIgnoreCase(bool.TrueString)) { return; } ProjectModelTasks.Initialize(); s_confirmedVersion = SuppressErrors(CheckAwareness, includeStackTrace: true); if (s_confirmedVersion == null) { return; } var configuration = TelemetryConfiguration.CreateDefault(); s_client = new TelemetryClient(configuration) { InstrumentationKey = InstrumentationKey }; s_client.Context.Session.Id = Guid.NewGuid().ToString(); s_client.Context.Location.Ip = "N/A"; s_client.Context.Cloud.RoleInstance = "N/A"; }
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); }
private static void UpdateBuildProject(AbsolutePath buildScript) { var configuration = GetConfiguration(buildScript, evaluate: true); var projectFile = configuration[BUILD_PROJECT_FILE]; ProjectModelTasks.Initialize(); ProjectUpdater.Update(projectFile); }
public Build() { NugetVersion = new Lazy <string>(GetNugetVersion); // This initialisation is required to ensure the build script can // perform actions such as GetRuntimeIdentifiers() on projects. ProjectModelTasks.Initialize(); }
/// <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")); }
public static int CakeConvert(string[] args, [CanBeNull] AbsolutePath rootDirectory, [CanBeNull] AbsolutePath buildScript) { PrintInfo(); Logging.Configure(); Telemetry.ConvertCake(); ProjectModelTasks.Initialize(); Host.Warning( new[] { "Converting .cake files is a best effort approach using syntax rewriting.", "Compile errors are to be expected, however, the following elements are currently covered:", " - Target definitions", " - Default targets", " - Parameter declarations", " - Absolute paths", " - Globbing patterns", " - Tool invocations (dotnet CLI, SignTool)", " - Addin and tool references", }.JoinNewLine()); Host.Debug(); if (!PromptForConfirmation("Continue?")) { return(0); } Host.Debug(); if (buildScript == null && PromptForConfirmation("Should a NUKE project be created for better results?")) { Setup(args, rootDirectory: null, buildScript: null); } var buildProjectFile = File.Exists(WorkingDirectory / CurrentBuildScriptName) ? GetConfiguration(WorkingDirectory / CurrentBuildScriptName, evaluate: true) .GetValueOrDefault(BUILD_PROJECT_FILE, defaultValue: null) : null; string GetOutputDirectory(string file) => Path.GetDirectoryName(buildProjectFile ?? file); string GetOutputFile(string file) => (AbsolutePath)GetOutputDirectory(file) / Path.GetFileNameWithoutExtension(file).Capitalize() + ".cs"; GetCakeFiles().ForEach(x => File.WriteAllText(path: GetOutputFile(x), contents: GetCakeConvertedContent(File.ReadAllText(x)))); if (buildProjectFile != null) { GetCakeFiles().SelectMany(x => GetCakePackages(File.ReadAllText(x))) .ForEach(x => AddOrReplacePackage(x.PackageId, x.PackageVersion, x.PackageType, buildProjectFile)); } return(0); }
public void ProjectTest() { var solution = ProjectModelTasks.ParseSolution(SolutionFile); var project = solution.Projects.Single(x => x.Name == "Nuke.Common"); var action = new Action(() => project.GetMSBuildProject()); action.Should().NotThrow(); project.GetTargetFrameworks().Should().HaveCount(2).And.Contain("netcoreapp2.1"); project.HasPackageReference("Glob").Should().BeTrue(); project.GetPackageReferenceVersion("YamlDotNet").Should().Be("11.2.1"); }
public void SolutionTest() { var solution = ProjectModelTasks.ParseSolution(SolutionFile); solution.Projects.Where(x => x.Is(ProjectType.SolutionFolder)).Select(x => x.Name) .Should().BeEquivalentTo("misc"); solution.Projects.Where(x => x.Is(ProjectType.CSharpProject)).Should().HaveCount(7); var buildProject = solution.Projects.SingleOrDefault(x => x.Name == "_build"); buildProject.Should().NotBeNull(); buildProject.Is(ProjectType.CSharpProject).Should().BeTrue(); }
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(); }
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); }
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(); }
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); }
public void SolutionGetProjectsTest() { var solution = ProjectModelTasks.ParseSolution(SolutionFile); solution.GetProjects("*.Tests").Should().HaveCount(2); }
public void ProjectTest() { var solution = ProjectModelTasks.ParseSolution(SolutionFile); solution.Projects.First().GetMSBuildProject(); }
/* * Solution ProtobufCSDLLSolutionDynamic * { * get * { * string rootAbsolutePath = ((AbsolutePath) (RootDirectory / * "ExampleCustomProtoBufStructure/ExampleCustomProtoBufStructure.csproj" * )); * rootAbsolutePath = PathConstruction.Combine(NukeBuild.RootDirectory, "ExampleCustomProtoBufStructure/ExampleCustomProtoBufStructure.csproj"); * //var solution = new Solution(); * //solution.Path = new DirectoryInfo(rootAbsolutePath); * return ProjectModelTasks.ParseSolution(rootAbsolutePath); * } * } */ public static Solution SolutionDynamic(AbsolutePath pathToProject) { return(ProjectModelTasks.ParseSolution(pathToProject)); }