/// <inheritdoc /> public void OnBuildCreated(NukeBuild build, IReadOnlyCollection <ExecutableTarget> executableTargets) { if (!NukeBuild.IsLocalBuild) { return; } // We only care on local machines if (HookNames.Any(hook => !FileExists(NukeBuild.RootDirectory / $".git/hooks/{hook}"))) { Logger.Info("Git hooks not found..."); if (FileExists(NukeBuild.RootDirectory / "package.json")) { Logger.Info("package.json found running npm install to see if that installs any hooks"); ProcessTasks.StartProcess(ToolPathResolver.GetPathExecutable("npm"), "install").AssertWaitForExit() .AssertZeroExitCode(); } } foreach (var hook in HookNames) { if (!FileExists(NukeBuild.RootDirectory / $".git/hooks/{hook}")) { Logger.Info($"Was unable to install {hook} hook."); } } }
static void RegisterMSBuildFromDotNet() { var dotnet = ToolPathResolver.TryGetEnvironmentExecutable("DOTNET_EXE") ?? ToolPathResolver.GetPathExecutable("dotnet"); string TryFromBasePath() { var output = ProcessTasks.StartProcess(dotnet, "--info", logInvocation: false, logOutput: false).AssertZeroExitCode().Output; return(output .Select(x => x.Text.Trim()) .SingleOrDefault(x => x.StartsWith("Base Path:")) ?.TrimStart("Base Path:").Trim()); } string TryFromSdkList() { var output = ProcessTasks.StartProcess(dotnet, "--list-sdks", logInvocation: false, logOutput: false).AssertZeroExitCode().Output; var latestInstalledSdkParts = output.Last().Text.Split(' '); return((AbsolutePath)latestInstalledSdkParts.ElementAt(1).Trim('[', ']') / latestInstalledSdkParts.ElementAt(0)); } var sdkDirectory = (AbsolutePath)(TryFromBasePath() ?? TryFromSdkList()); MSBuildLocator.RegisterMSBuildPath(sdkDirectory); }
public static void ManualToolresolvingMeandering() { string TryGetPathExe(string exe) { try { return(ToolPathResolver.GetPathExecutable(exe)); } catch { } return(string.Empty); } string TryGetPathToolExe(string exe) { try { return(ToolPathResolver.TryGetEnvironmentExecutable(exe)); } catch { } return(string.Empty); } //ToolResolver.GetPathTool(exe) //ToolResolver.GetPathTool("appveyor"); //Tool myTool = ToolResolver.GetPathTool(exe) void TryAndGetPathEXEAndPrint(string exe) { Logger.Normal($"Trying to get exe {exe}: '{TryGetPathExe(exe)}'"); } var executables = new[] { "DOES NOT EXIST", "powershell", "bash" }; //ToolPathResolver.GetPathExecutable - get something on the path //vs TryGetEnvironmentExecutable //ToolPathResolver.TryGetEnvironmentExecutable -- this will get an exe defined by an enviornment variable //vs ToolResolver.GetPathTool(exe) - get a tool in the user's path based on executables.ForEach(TryAndGetPathEXEAndPrint); Logger.Normal($"Comspec is set up by something on windows systems as a standard exe tool, so here is the path {TryGetPathToolExe("ComSpec")}"); Tool git = ToolResolver.GetPathTool("git"); #pragma warning disable 168 //just showing that ControlFlow.Fail throws an "Exception" object that is not sub-typed try { Tool doesNotExist = ToolResolver.GetPathTool("DOES NOT EXIST"); }catch (Exception e) {} try { ControlFlow.Fail("TEST same as trying to get non existent tool with tool resolver"); }catch (Exception e) {} #pragma warning restore 168 }
/// <summary> /// Constructor /// </summary> /// <param name="rootPath"></param> /// <param name="gitVersion"></param> public GitProcessor(AbsolutePath rootPath) { RootDirectory = rootPath; DotNetPath = ToolPathResolver.GetPathExecutable("dotnet"); IdentifyMainBranch(); Fetch_GitVersion(); PrintGitCommandVersion(); }
private static void Initialize(string workingDirectory) { var dotnet = ToolPathResolver.TryGetEnvironmentExecutable("DOTNET_EXE") ?? ToolPathResolver.GetPathExecutable("dotnet"); var output = ProcessTasks.StartProcess(dotnet, "--info", workingDirectory, logOutput: false).AssertZeroExitCode().Output; var basePath = (PathConstruction.AbsolutePath)output .Select(x => x.Text.Trim()) .Single(x => x.StartsWith("Base Path:")) .TrimStart("Base Path:").Trim(); EnvironmentInfo.SetVariable("MSBUILD_EXE_PATH", basePath / "MSBuild.dll"); }
private static Process Build(string buildScript, string arguments) { return(Process.Start( new ProcessStartInfo { FileName = EnvironmentInfo.IsWin ? ToolPathResolver.GetPathExecutable("powershell") : ToolPathResolver.GetPathExecutable("bash"), Arguments = EnvironmentInfo.IsWin ? $"-ExecutionPolicy ByPass -NoProfile -File {buildScript} {arguments}" : $"{buildScript} {arguments}" }).NotNull()); }
/// <summary> /// Constructor /// </summary> public PreStage_ConvertToSlugCI(CISession ciSession) : base(BuildStageStatic.PRESTAGE_CONVERT_TO_SLUGCI, ciSession) { // Set expected directories. ExpectedSolutionPath = CISession.SourceDirectory; DotNetPath = ToolPathResolver.GetPathExecutable("dotnet"); if (ciSession.IsFastStart) { // TODO - Need to restore this at some point, but needs to write to a AddOutputStage instead of screen. It interferes with prompting. // Misc.WriteSubHeader("FastStart: Skipping normal checks and validations"); } }
private static Process Build(string buildScript, string arguments) { var startInfo = new ProcessStartInfo { FileName = EnvironmentInfo.IsWin ? ToolPathResolver.GetPathExecutable("powershell") : ToolPathResolver.GetPathExecutable("bash"), Arguments = EnvironmentInfo.IsWin ? $"-ExecutionPolicy ByPass -NoProfile -File {buildScript.DoubleQuoteIfNeeded()} {arguments}" : $"{buildScript} {arguments}" }; startInfo.Environment[Constants.GlobalToolVersionEnvironmentKey] = typeof(Program).Assembly.GetVersionText(); startInfo.Environment[Constants.GlobalToolStartTimeEnvironmentKey] = DateTime.Now.ToString("O"); return(Process.Start(startInfo).NotNull()); }
private void GenerateClient(string language) { var generatorPath = SourceDirectory / "Dangl.AVACloudClientGenerator" / "bin" / Configuration / "net5.0" / "Dangl.AVACloudClientGenerator.dll"; var outputPath = OutputDirectory / language; var arguments = $"\"{generatorPath}\" -l {language} -o \"{outputPath}\""; if (!string.IsNullOrWhiteSpace(CustomSwaggerDefinitionUrl)) { Serilog.Log.Information("Using custom Swagger definition url: " + CustomSwaggerDefinitionUrl); arguments += $" -u {CustomSwaggerDefinitionUrl}"; } StartProcess(ToolPathResolver.GetPathExecutable("dotnet"), arguments) .AssertZeroExitCode(); System.IO.Compression.ZipFile.CreateFromDirectory(outputPath, outputPath.ToString().TrimEnd('/').TrimEnd('\\') + ".zip"); }
public static string GetToolPath() { return(ToolPathResolver.TryGetEnvironmentExecutable("DOTNET_EXE") ?? ToolPathResolver.GetPathExecutable("dotnet")); }
/// <summary> /// Ensure the Directory Structure is correct. Projects are in proper place. /// </summary> /// <param name="solutionFile"></param> /// <returns></returns> private bool ProperDirectoryStructure(string solutionFile) { // Create src folder if it does not exist. if (!DirectoryExists(SourceDirectory)) { Directory.CreateDirectory(SourceDirectory.ToString()); } // Create Tests folder if it does not exist. if (!DirectoryExists(TestsDirectory)) { Directory.CreateDirectory(TestsDirectory.ToString()); } // Create Artifacts / Output folder if it does not exist. if (!DirectoryExists(OutputDirectory)) { Directory.CreateDirectory(OutputDirectory.ToString()); } // Query the solution for the projects that are in it. // We allow all tests to run, instead of failing at first failure. CurrentSolutionPath = (AbsolutePath)Path.GetDirectoryName(solutionFile); DotNetPath = ToolPathResolver.GetPathExecutable("dotnet"); IProcess slnfind = ProcessTasks.StartProcess(DotNetPath, "sln " + CurrentSolutionPath + " list", logOutput: true); slnfind.AssertWaitForExit(); IReadOnlyCollection <Output> output = slnfind.Output; // There are 2 things we need to check. // 1. Is solution in right folder? // 2. Are projects in right folder. // The Move process has to do the following: // 1. Move the project folder to proper place // 2. Remove the project from the solution // 3. Do steps 1, 2 for every project // 4. Move solution file to proper location // 5. Re-add all projects to solution bool solutionNeedsToMove = false; if (CurrentSolutionPath.ToString() != ExpectedSolutionPath.ToString()) { solutionNeedsToMove = true; } List <VisualStudioProject> movedProjects = new List <VisualStudioProject>(); // Step 3 foreach (Output outputRec in output) { if (outputRec.Text.EndsWith(".csproj")) { VisualStudioProject project = GetInitProject(outputRec.Text); Projects.Add(project); // Do we need to move the project? if ((project.OriginalPath.ToString() != project.NewPath.ToString()) || solutionNeedsToMove) { movedProjects.Add(project); MoveProjectStepA(project); } } } // Step 4: Is Solution in proper directory. If not move it. if (solutionNeedsToMove) { string slnFileCurrent = CurrentSolutionPath / Path.GetFileName(solutionFile); string slnFileFuture = ExpectedSolutionPath / Path.GetFileName(solutionFile); File.Move(slnFileCurrent, slnFileFuture); } // Step 5. Read project to solution if (movedProjects.Count > 0) { foreach (VisualStudioProject project in movedProjects) { MoveProjectStepB(project); } } return(true); }
internal static string GetToolPath() { return(ToolPathResolver.GetPathExecutable(EnvironmentInfo.IsWin ? "powershell" : "pwsh")); }