public void Execute() { log.Info($"Running on {(RunningOnUnix ? "Unix" : "Windows")}."); var variables = gitVersionCalculator.CalculateVersionVariables(); var arguments = options.Value; switch (arguments.Output) { case OutputType.BuildServer: var buildServer = buildServerResolver.Resolve(); buildServer?.WriteIntegration(Console.WriteLine, variables); break; case OutputType.Json: switch (arguments.ShowVariable) { case null: Console.WriteLine(variables.ToString()); break; default: if (!variables.TryGetValue(arguments.ShowVariable, out var part)) { throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); } Console.WriteLine(part); break; } break; default: throw new ArgumentOutOfRangeException(); } if (arguments.UpdateWixVersionFile) { using var wixVersionFileUpdater = new WixVersionFileUpdater(arguments.TargetPath, variables, fileSystem, log); wixVersionFileUpdater.Update(); } using var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, arguments.TargetPath, variables, fileSystem, log, arguments.EnsureAssemblyInfo); if (arguments.UpdateAssemblyInfo) { assemblyInfoUpdater.Update(); assemblyInfoUpdater.CommitChanges(); } RunExecCommandIfNeeded(arguments, arguments.TargetPath, variables, log); RunMsBuildIfNeeded(arguments, arguments.TargetPath, variables, log); }
public static void Run(Arguments arguments, IFileSystem fileSystem) { Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows")); var noFetch = arguments.NoFetch; var authentication = arguments.Authentication; var targetPath = arguments.TargetPath; var targetUrl = arguments.TargetUrl; var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null; var noCache = arguments.NoCache; var pathFilter = arguments.PathFilter; var executeCore = new ExecuteCore(fileSystem); var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache, pathFilter); if (arguments.Output == OutputType.BuildServer) { foreach (var buildServer in BuildServerList.GetApplicableBuildServers()) { buildServer.WriteIntegration(Console.WriteLine, variables); } } if (arguments.Output == OutputType.Json) { switch (arguments.ShowVariable) { case null: Console.WriteLine(JsonOutputFormatter.ToJson(variables)); break; default: string part; if (!variables.TryGetValue(arguments.ShowVariable, out part)) { throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); } Console.WriteLine(part); break; } } using (var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, targetPath, variables, fileSystem, arguments.EnsureAssemblyInfo)) { if (arguments.UpdateAssemblyInfo) { assemblyInfoUpdater.Update(); } var execRun = false; var msbuildRun = false; #if NETDESKTOP execRun = RunExecCommandIfNeeded(arguments, targetPath, variables); msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables); #endif if (!execRun && !msbuildRun) { assemblyInfoUpdater.CommitChanges(); //TODO Put warning back //if (!context.CurrentBuildServer.IsRunningInBuildAgent()) //{ // Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed"); // Console.WriteLine(); // Console.WriteLine("Run GitVersion.exe /? for help"); //} } } }
public void Execute() { log.Info($"Running on {(RunningOnUnix ? "Unix" : "Windows")}."); var variables = gitVersionCalculator.CalculateVersionVariables(); switch (arguments.Output) { case OutputType.BuildServer: { var buildServer = buildServerResolver.Resolve(); buildServer?.WriteIntegration(Console.WriteLine, variables); break; } case OutputType.Json: switch (arguments.ShowVariable) { case null: Console.WriteLine(JsonOutputFormatter.ToJson(variables)); break; default: if (!variables.TryGetValue(arguments.ShowVariable, out var part)) { throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); } Console.WriteLine(part); break; } break; default: throw new ArgumentOutOfRangeException(); } if (arguments.UpdateWixVersionFile) { using var wixVersionFileUpdater = new WixVersionFileUpdater(arguments.TargetPath, variables, fileSystem, log); wixVersionFileUpdater.Update(); } using var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, arguments.TargetPath, variables, fileSystem, log, arguments.EnsureAssemblyInfo); if (arguments.UpdateAssemblyInfo) { assemblyInfoUpdater.Update(); } var execRun = RunExecCommandIfNeeded(arguments, arguments.TargetPath, variables, log); var msbuildRun = RunMsBuildIfNeeded(arguments, arguments.TargetPath, variables, log); if (!execRun && !msbuildRun) { assemblyInfoUpdater.CommitChanges(); //TODO Put warning back //if (!context.CurrentBuildServer.IsRunningInBuildAgent()) //{ // Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed"); // Console.WriteLine(); // Console.WriteLine("Run GitVersion.exe /? for help"); //} } }
public void Execute(Arguments arguments, IFileSystem fileSystem, IEnvironment environment, ILog log, IConfigFileLocator configFileLocator) { log.Info($"Running on {(runningOnUnix ? "Unix" : "Windows")}."); var noFetch = arguments.NoFetch; var authentication = arguments.Authentication; var targetPath = arguments.TargetPath; var targetUrl = arguments.TargetUrl; var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation; var targetBranch = arguments.TargetBranch; var commitId = arguments.CommitId; var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null; var noCache = arguments.NoCache; var noNormalize = arguments.NoNormalize; var executeCore = new ExecuteCore(fileSystem, environment, log, configFileLocator); var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache, noNormalize); switch (arguments.Output) { case OutputType.BuildServer: { BuildServerList.Init(environment, log); foreach (var buildServer in BuildServerList.GetApplicableBuildServers(log)) { buildServer.WriteIntegration(Console.WriteLine, variables); } break; } case OutputType.Json: switch (arguments.ShowVariable) { case null: Console.WriteLine(JsonOutputFormatter.ToJson(variables)); break; default: if (!variables.TryGetValue(arguments.ShowVariable, out var part)) { throw new WarningException($"'{arguments.ShowVariable}' variable does not exist"); } Console.WriteLine(part); break; } break; default: throw new ArgumentOutOfRangeException(); } if (arguments.UpdateWixVersionFile) { using (var wixVersionFileUpdater = new WixVersionFileUpdater(targetPath, variables, fileSystem, log)) { wixVersionFileUpdater.Update(); } } using (var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, targetPath, variables, fileSystem, log, arguments.EnsureAssemblyInfo)) { if (arguments.UpdateAssemblyInfo) { assemblyInfoUpdater.Update(); } var execRun = RunExecCommandIfNeeded(arguments, targetPath, variables, log); var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables, log); if (!execRun && !msbuildRun) { assemblyInfoUpdater.CommitChanges(); //TODO Put warning back //if (!context.CurrentBuildServer.IsRunningInBuildAgent()) //{ // Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed"); // Console.WriteLine(); // Console.WriteLine("Run GitVersion.exe /? for help"); //} } } }