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); }
public void OnBuildFinished(NukeBuild build) { if (NukeBuild.IsServerBuild) { DotNetTasks.DotNet("build-server shutdown", logInvocation: EnableLogging, logOutput: EnableLogging); } }
public void OnBuildFinished(NukeBuild build) { if (NukeBuild.Host != HostType) { return; } // Note https://github.com/dotnet/cli/issues/11424 if (ShutdownDotNetBuildServer) { DotNetTasks.DotNet("build-server shutdown"); } OnBuildFinishedInternal(build); }
/// <summary> /// Parses a project file. /// </summary> /// <param name="projectFile">The project path.</param> /// <param name="configuration"></param> /// <param name="runtimeValue"></param> /// <returns>The parsed project.</returns> public ProjectParseResult Parse(string projectFile, string configuration, string runtimeValue) { // Get the project file. var pf = Path.GetTempFileName(); try { DotNetTasks.DotNet($"msbuild -preprocess:{pf} {projectFile.DoubleQuoteIfNeeded()}"); XDocument document = XDocument.Load(pf); if (document.Root == null) { throw new Exception( "Silly error: The parser should never make the root element of a document into a null value"); } var projectProperties = new Dictionary <string, string>(); projectProperties.Add("Platform", runtimeValue); projectProperties.Add("Configuration", configuration); // Parsing the build file is sensitive to the declared order of elements. // If there are include files, then these files must be honored too. ParseProjectProperties(document, configuration, runtimeValue, projectProperties); var targetFrameworks = GetValueOrDefault(projectProperties, "TargetFrameworks"); if (string.IsNullOrEmpty(targetFrameworks)) { targetFrameworks = GetValueOrDefault(projectProperties, "TargetFramework"); } targetFrameworks ??= ""; var targetFrameworksList = targetFrameworks.Split(";"); var name = Path.GetFileNameWithoutExtension(projectFile); return(new ProjectParseResult(name, GetValueOrDefault(projectProperties, "Configuration"), GetValueOrDefault(projectProperties, "OutputType", "Library"), targetFrameworksList)); } finally { File.Delete(pf); } }
private static void UpdateGlobalJsonFile(AbsolutePath rootDirectory) { var latestInstalledSdk = DotNetTasks.DotNet("--list-sdks", logInvocation: false, logOutput: false) .LastOrDefault().Text?.Split(" ").First(); if (latestInstalledSdk == null) { return; } var globalJsonFile = rootDirectory / "global.json"; var jobject = File.Exists(globalJsonFile) ? SerializationTasks.JsonDeserializeFromFile <JObject>(globalJsonFile) : new JObject(); jobject["sdk"] ??= new JObject(); jobject["sdk"].NotNull()["version"] = latestInstalledSdk; SerializationTasks.JsonSerializeToFile(jobject, globalJsonFile); }
public static IReadOnlyCollection <Output> DotNetBuildTestSolution( string solutionFile, IEnumerable <Project> projects) { if (File.Exists(solutionFile)) { return(Array.Empty <Output>()); } var workingDirectory = Path.GetDirectoryName(solutionFile); var list = new List <Output>(); list.AddRange(DotNetTasks.DotNet($"new sln -n {Path.GetFileNameWithoutExtension(solutionFile)}", workingDirectory)); var projectsArg = string.Join(" ", projects.Select(t => $"\"{t}\"")); list.AddRange(DotNetTasks.DotNet($"sln \"{solutionFile}\" add {projectsArg}", workingDirectory)); return(list); }
public static IReadOnlyCollection <Output> DotNetBuildSonarSolution( string solutionFile, IEnumerable <string> directories = null, Func <string, bool> include = null) { if (File.Exists(solutionFile)) { return(Array.Empty <Output>()); } directories ??= Directories; IEnumerable <string> projects = GetAllProjects(Path.GetDirectoryName(solutionFile), directories, include); var workingDirectory = Path.GetDirectoryName(solutionFile); var list = new List <Output>(); list.AddRange(DotNetTasks.DotNet($"new sln -n {Path.GetFileNameWithoutExtension(solutionFile)}", workingDirectory)); var projectsArg = string.Join(" ", projects.Select(t => $"\"{t}\"")); list.AddRange(DotNetTasks.DotNet($"sln \"{solutionFile}\" add {projectsArg}", workingDirectory)); return(list); }
public void OnBuildFinished(NukeBuild build) { // Note https://github.com/dotnet/cli/issues/11424 DotNetTasks.DotNet("build-server shutdown"); }