Exemple #1
0
        /// <summary>
        /// Ensures that GitVersion has a system wide environment variable set.  If not it will attempt to locate it and set the environment variable.
        /// </summary>
        /// <param name="targetEnvironment">Whether to target user or system/machine setting.  You must run the app as administrator to use Machine.</param>
        /// <returns></returns>
        public static bool ValidateGetVersionEnvVariable(EnvironmentVariableTarget targetEnvironment = EnvironmentVariableTarget.Process)
        {
            string envGitVersion = Environment.GetEnvironmentVariable(ENV_GITVERSION);


            if (envGitVersion == null)
            {
                Logger.Warn("GitVersion environment variable not found.  Will attempt to set.");

                string cmd     = "where";
                string cmdArgs = "gitversion.exe";

                IProcess process = ProcessTasks.StartProcess(cmd, cmdArgs, logOutput: true);
                process.AssertWaitForExit();
                ControlFlow.Assert(process.ExitCode == 0, "The " + ENV_GITVERSION + " environment variable is not set and attempt to fix it, failed because it appears GitVersion is not installed on the local machine.  Install it and then re-run and/or set the environment variable manually");

                // Set the environment variable now that we found it
                string value = process.Output.First().Text;
                Environment.SetEnvironmentVariable(ENV_GITVERSION, value, targetEnvironment);
                envGitVersion = Environment.GetEnvironmentVariable(ENV_GITVERSION);
                string val = ToolPathResolver.TryGetEnvironmentExecutable("GITVERSION_EXE");
                Console.WriteLine("Toolpathresolver: " + val);
                Console.WriteLine();
                string msg =
                    "GitVersion Environment variable has been set!  You will need to ensure you close the current console window before continuing to pickup the change.";
                Console.WriteWithGradient(msg, Color.Fuchsia, Color.Yellow, 16);
                Console.ReplaceAllColorsWithDefaults();
            }

            return(true);
        }
Exemple #2
0
            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
        }
Exemple #4
0
        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");
        }
Exemple #5
0
 private static string GetToolPath()
 {
     return(ToolPathResolver.TryGetEnvironmentExecutable("NUGET_EXE")
            ?? ToolPathResolver.GetPackageExecutable("NuGet.CommandLine", "nuget.exe"));
 }
Exemple #6
0
 public static string GetToolPath()
 {
     return(ToolPathResolver.TryGetEnvironmentExecutable("DOTNET_EXE")
            ?? ToolPathResolver.GetPathExecutable("dotnet"));
 }