diff --git a/src/GitVersionCore.Tests/ConfigProviderTests.cs b/src/GitVersionCore.Tests/ConfigProviderTests.cs index 933aa2cd5d..955350d46c 100644 --- a/src/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/src/GitVersionCore.Tests/ConfigProviderTests.cs @@ -96,7 +96,7 @@ public void RegexIsRequired() tag: bugfix"; SetupConfigFileContent(text); var ex = Should.Throw(() => configProvider.Provide(repoPath)); - ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'regex'\n\n" + + ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'regex'{System.Environment.NewLine}" + "See https://gitversion.net/docs/configuration/ for more info"); } @@ -111,7 +111,7 @@ public void SourceBranchIsRequired() tag: bugfix"; SetupConfigFileContent(text); var ex = Should.Throw(() => configProvider.Provide(repoPath)); - ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'source-branches'\n\n" + + ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'source-branches'{System.Environment.NewLine}" + "See https://gitversion.net/docs/configuration/ for more info"); } diff --git a/src/GitVersionCore.Tests/VariableProviderTests.cs b/src/GitVersionCore.Tests/VariableProviderTests.cs index 33c74a2cfd..923afd6895 100644 --- a/src/GitVersionCore.Tests/VariableProviderTests.cs +++ b/src/GitVersionCore.Tests/VariableProviderTests.cs @@ -43,7 +43,9 @@ public void ShouldLogWarningWhenUsingDefaultInformationalVersionInCustomFormat() Patch = 3, }; +#pragma warning disable CS0618 // Type or member is obsolete var propertyName = nameof(SemanticVersionFormatValues.DefaultInformationalVersion); +#pragma warning restore CS0618 // Type or member is obsolete var config = new TestEffectiveConfiguration(assemblyInformationalFormat: $"{{{propertyName}}}"); variableProvider.GetVariablesFor(semVer, config, false); logMessages.ShouldContain(message => message.Trim().StartsWith("WARN") && message.Contains(propertyName), 1, $"Expected a warning to be logged when using the variable {propertyName} in a configuration format template"); diff --git a/src/GitVersionCore/BuildServers/TeamCity.cs b/src/GitVersionCore/BuildServers/TeamCity.cs index 435d400a61..b6740dcb7d 100644 --- a/src/GitVersionCore/BuildServers/TeamCity.cs +++ b/src/GitVersionCore/BuildServers/TeamCity.cs @@ -34,11 +34,8 @@ public override string GetCurrentBranch(bool usingDynamicRepos) private void WriteBranchEnvVariableWarning() { Log.Warning(@"TeamCity doesn't make the current branch available through environmental variables. - Depending on your authentication and transport setup of your git VCS root things may work. In that case, ignore this warning. - In your TeamCity build configuration, add a parameter called `env.Git_Branch` with value %teamcity.build.vcs.branch.% - See https://gitversion.net/docs/build-server-support/build-server/teamcity for more info"); } diff --git a/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs b/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs index 4073622fa3..0231dd63cb 100644 --- a/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs +++ b/src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs @@ -145,7 +145,7 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi } var branchName = chosenBranch.FriendlyName; - log.Warning(errorMessage + System.Environment.NewLine + System.Environment.NewLine + "Falling back to " + branchName + " branch config"); + log.Warning(errorMessage + System.Environment.NewLine + "Falling back to " + branchName + " branch config"); // To prevent infinite loops, make sure that a new branch was chosen. if (targetBranch.IsSameBranch(chosenBranch)) diff --git a/src/GitVersionCore/Configuration/ConfigExtensions.cs b/src/GitVersionCore/Configuration/ConfigExtensions.cs index c2ef59c41c..ab1f199002 100644 --- a/src/GitVersionCore/Configuration/ConfigExtensions.cs +++ b/src/GitVersionCore/Configuration/ConfigExtensions.cs @@ -88,14 +88,14 @@ public static void Reset(this Config config) var regex = branchConfig.Value.Regex; if (regex == null) { - throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'regex'\n\n" + + throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'regex'{System.Environment.NewLine}" + "See https://gitversion.net/docs/configuration/ for more info"); } var sourceBranches = branchConfig.Value.SourceBranches; if (sourceBranches == null) { - throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'source-branches'\n\n" + + throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'source-branches'{System.Environment.NewLine}" + "See https://gitversion.net/docs/configuration/ for more info"); } @@ -189,7 +189,7 @@ public static BranchConfig GetConfigForBranch(this Config config, string branchN } catch (InvalidOperationException) { - var matchingConfigs = String.Concat(matches.Select(m => $"\n - {m.Key}")); + var matchingConfigs = String.Concat(matches.Select(m => $"{System.Environment.NewLine} - {m.Key}")); var picked = matches .Select(kvp => kvp.Value) .First(); diff --git a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs index 0dbc18c645..f9e5a6d9af 100644 --- a/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs +++ b/src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs @@ -46,7 +46,7 @@ protected override string GetPrompt(Config config, string workingDirectory) return @"Which branch would you like to configure: 0) Go Back -" + string.Join("\r\n", OrderedBranches(config).Select((c, i) => $"{i + 1}) {c.Key}")); +" + string.Join(System.Environment.NewLine, OrderedBranches(config).Select((c, i) => $"{i + 1}) {c.Key}")); } private static IOrderedEnumerable> OrderedBranches(Config config) diff --git a/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs b/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs index ceb47047b4..2e41b02990 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs @@ -10,7 +10,7 @@ public FinishedSetupStep(IConsole console, IFileSystem fileSystem, ILog log, ICo protected override string GetPrompt(Config config, string workingDirectory) { - return "Questions are all done, you can now edit GitVersion's configuration further\r\n" + base.GetPrompt(config, workingDirectory); + return $"Questions are all done, you can now edit GitVersion's configuration further{System.Environment.NewLine}" + base.GetPrompt(config, workingDirectory); } } } diff --git a/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs b/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs index 0e00c2df32..c88154b8e1 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs @@ -11,7 +11,7 @@ public GitFlowSetupStep(IConsole console, IFileSystem fileSystem, ILog log, ICon protected override string GetPrompt(Config config, string workingDirectory) { - return "By default GitVersion will only increment the version of the 'develop' branch every commit, all other branches will increment when tagged\r\n\r\n" + + return $"By default GitVersion will only increment the version of the 'develop' branch every commit, all other branches will increment when tagged{System.Environment.NewLine}{System.Environment.NewLine}" + base.GetPrompt(config, workingDirectory); } } diff --git a/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs b/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs index cb09a2464c..901d662745 100644 --- a/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs +++ b/src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs @@ -11,7 +11,7 @@ public GitHubFlowStep(IConsole console, IFileSystem fileSystem, ILog log, IConfi protected override string GetPrompt(Config config, string workingDirectory) { - return "By default GitVersion will only increment the version when tagged\r\n\r\n" + base.GetPrompt(config, workingDirectory); + return $"By default GitVersion will only increment the version when tagged{System.Environment.NewLine}{System.Environment.NewLine}" + base.GetPrompt(config, workingDirectory); } } } diff --git a/src/GitVersionCore/GitRepoMetadataProvider.cs b/src/GitVersionCore/GitRepoMetadataProvider.cs index ddc80558da..d2e77fd895 100644 --- a/src/GitVersionCore/GitRepoMetadataProvider.cs +++ b/src/GitVersionCore/GitRepoMetadataProvider.cs @@ -218,8 +218,8 @@ public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch if (possibleBranches.Count > 1) { var first = possibleBranches.First(); - log.Info($"Multiple source branches have been found, picking the first one ({first.Branch.FriendlyName}).\n" + - "This may result in incorrect commit counting.\nOptions were:\n " + + log.Info($"Multiple source branches have been found, picking the first one ({first.Branch.FriendlyName}).{System.Environment.NewLine}" + + $"This may result in incorrect commit counting.{System.Environment.NewLine}Options were:{System.Environment.NewLine}" + string.Join(", ", possibleBranches.Select(b => b.Branch.FriendlyName))); return first; } diff --git a/src/GitVersionCore/Helpers/GitRepositoryHelper.cs b/src/GitVersionCore/Helpers/GitRepositoryHelper.cs index 7529c99190..582955e756 100644 --- a/src/GitVersionCore/Helpers/GitRepositoryHelper.cs +++ b/src/GitVersionCore/Helpers/GitRepositoryHelper.cs @@ -62,7 +62,7 @@ public static void NormalizeGitDirectory(ILog log, IEnvironment environment, str } log.Info($"HEAD is detached and points at commit '{headSha}'."); - log.Info(string.Format("Local Refs:\r\n" + string.Join(System.Environment.NewLine, repo.Refs.FromGlob("*").Select(r => $"{r.CanonicalName} ({r.TargetIdentifier})")))); + log.Info($"Local Refs:{System.Environment.NewLine}" + string.Join(System.Environment.NewLine, repo.Refs.FromGlob("*").Select(r => $"{r.CanonicalName} ({r.TargetIdentifier})"))); // In order to decide whether a fake branch is required or not, first check to see if any local branches have the same commit SHA of the head SHA. // If they do, go ahead and checkout that branch @@ -203,7 +203,7 @@ private static void CreateFakeBranchPointingAtThePullRequestTip(ILog log, Reposi GetRemoteTipsUsingUsernamePasswordCredentials(repo, remote, authentication.Username, authentication.Password)) .ToList(); - log.Info("Remote Refs:\r\n" + string.Join(System.Environment.NewLine, remoteTips.Select(r => r.CanonicalName))); + log.Info($"Remote Refs:{System.Environment.NewLine}" + string.Join(System.Environment.NewLine, remoteTips.Select(r => r.CanonicalName))); var headTipSha = repo.Head.Tip.Sha; diff --git a/src/GitVersionCore/Logging/FileAppender.cs b/src/GitVersionCore/Logging/FileAppender.cs index 6d440772ff..9f0c4ae33d 100644 --- a/src/GitVersionCore/Logging/FileAppender.cs +++ b/src/GitVersionCore/Logging/FileAppender.cs @@ -37,7 +37,7 @@ public void WriteTo(LogLevel level, string message) private static void WriteLogEntry(string logFilePath, string str) { - var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}\r\n"; + var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}{System.Environment.NewLine}"; File.AppendAllText(logFilePath, contents); } } diff --git a/src/GitVersionCore/Logging/Log.cs b/src/GitVersionCore/Logging/Log.cs index 489bd4da5b..51021ddab7 100644 --- a/src/GitVersionCore/Logging/Log.cs +++ b/src/GitVersionCore/Logging/Log.cs @@ -41,7 +41,7 @@ public void Write(Verbosity verbosity, LogLevel level, string format, params obj appender.WriteTo(level, formattedString); } - sb.Append(formattedString); + sb.AppendLine(formattedString); } public IDisposable IndentLog(string operationDescription) diff --git a/src/GitVersionCore/OutputVariables/VariableProvider.cs b/src/GitVersionCore/OutputVariables/VariableProvider.cs index 4a9fadc0b1..6808ba5be9 100644 --- a/src/GitVersionCore/OutputVariables/VariableProvider.cs +++ b/src/GitVersionCore/OutputVariables/VariableProvider.cs @@ -154,7 +154,9 @@ private string CheckAndFormatString(string formatString, T source, IEnvironme private void WarnIfUsingObsoleteFormatValues(string formatString) { +#pragma warning disable CS0618 // Type or member is obsolete var obsoletePropertyName = nameof(SemanticVersionFormatValues.DefaultInformationalVersion); +#pragma warning restore CS0618 // Type or member is obsolete if (formatString.Contains($"{{{obsoletePropertyName}}}")) { log.Write(LogLevel.Warn, $"Use format variable '{nameof(SemanticVersionFormatValues.InformationalVersion)}' instead of '{obsoletePropertyName}' which is obsolete and will be removed in a future release."); diff --git a/src/GitVersionExe.Tests/ArgumentParserTests.cs b/src/GitVersionExe.Tests/ArgumentParserTests.cs index c279ae11ca..20847daf85 100644 --- a/src/GitVersionExe.Tests/ArgumentParserTests.cs +++ b/src/GitVersionExe.Tests/ArgumentParserTests.cs @@ -59,7 +59,9 @@ public void HMeansIsHelp() public void Exec() { var arguments = argumentParser.ParseArguments("-exec rake"); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Exec.ShouldBe("rake"); +#pragma warning restore CS0612 // Type or member is obsolete } [Test] @@ -72,15 +74,19 @@ public void ExecWithArgs() "-execargs", "clean build" }); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Exec.ShouldBe("rake"); arguments.ExecArgs.ShouldBe("clean build"); +#pragma warning restore CS0612 // Type or member is obsolete } [Test] public void Msbuild() { var arguments = argumentParser.ParseArguments("-proj msbuild.proj"); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Proj.ShouldBe("msbuild.proj"); +#pragma warning restore CS0612 // Type or member is obsolete } [Test] @@ -93,8 +99,10 @@ public void MsbuildWithArgs() "-projargs", "/p:Configuration=Debug /p:Platform=AnyCPU" }); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Proj.ShouldBe("msbuild.proj"); arguments.ProjArgs.ShouldBe("/p:Configuration=Debug /p:Platform=AnyCPU"); +#pragma warning restore CS0612 // Type or member is obsolete } [Test] @@ -102,7 +110,9 @@ public void ExecwithTargetdirectory() { var arguments = argumentParser.ParseArguments("targetDirectoryPath -exec rake"); arguments.TargetPath.ShouldBe("targetDirectoryPath"); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Exec.ShouldBe("rake"); +#pragma warning restore CS0612 // Type or member is obsolete } [Test] @@ -374,7 +384,9 @@ public void OtherArgumentsCanBeParsedAfterNofetch() { var arguments = argumentParser.ParseArguments("-nofetch -proj foo.sln"); arguments.NoFetch.ShouldBe(true); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Proj.ShouldBe("foo.sln"); +#pragma warning restore CS0612 // Type or member is obsolete } [Test] @@ -382,7 +394,9 @@ public void OtherArgumentsCanBeParsedAfterNonormalize() { var arguments = argumentParser.ParseArguments("-nonormalize -proj foo.sln"); arguments.NoNormalize.ShouldBe(true); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Proj.ShouldBe("foo.sln"); +#pragma warning restore CS0612 // Type or member is obsolete } [Test] @@ -390,7 +404,9 @@ public void OtherArgumentsCanBeParsedAfterNocache() { var arguments = argumentParser.ParseArguments("-nocache -proj foo.sln"); arguments.NoCache.ShouldBe(true); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Proj.ShouldBe("foo.sln"); +#pragma warning restore CS0612 // Type or member is obsolete } [TestCase("-nofetch -nonormalize -nocache")] diff --git a/src/GitVersionExe/ArgumentParser.cs b/src/GitVersionExe/ArgumentParser.cs index e85c536885..73411317b2 100644 --- a/src/GitVersionExe/ArgumentParser.cs +++ b/src/GitVersionExe/ArgumentParser.cs @@ -149,7 +149,9 @@ public Arguments ParseArguments(string[] commandLineArguments) if (name.IsSwitch("exec")) { EnsureArgumentValueCount(values); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Exec = value; +#pragma warning restore CS0612 // Type or member is obsolete continue; } @@ -157,21 +159,27 @@ public Arguments ParseArguments(string[] commandLineArguments) if (name.IsSwitch("execargs")) { EnsureArgumentValueCount(values); +#pragma warning disable CS0612 // Type or member is obsolete arguments.ExecArgs = value; +#pragma warning restore CS0612 // Type or member is obsolete continue; } if (name.IsSwitch("proj")) { EnsureArgumentValueCount(values); +#pragma warning disable CS0612 // Type or member is obsolete arguments.Proj = value; +#pragma warning restore CS0612 // Type or member is obsolete continue; } if (name.IsSwitch("projargs")) { EnsureArgumentValueCount(values); +#pragma warning disable CS0612 // Type or member is obsolete arguments.ProjArgs = value; +#pragma warning restore CS0612 // Type or member is obsolete continue; } @@ -238,8 +246,8 @@ public Arguments ParseArguments(string[] commandLineArguments) if (versionVariable == null) { - var messageFormat = "{0} requires a valid version variable. Available variables are:\n{1}"; - var message = string.Format(messageFormat, name, string.Join(", ", VersionVariables.AvailableVariables.Select(x => string.Concat("'", x, "'")))); + var message = $"{name} requires a valid version variable. Available variables are:{System.Environment.NewLine}" + + string.Join(", ", VersionVariables.AvailableVariables.Select(x => string.Concat("'", x, "'"))); throw new WarningException(message); } diff --git a/src/GitVersionExe/ExecCommand.cs b/src/GitVersionExe/ExecCommand.cs index 8098f48ff9..5df365d076 100644 --- a/src/GitVersionExe/ExecCommand.cs +++ b/src/GitVersionExe/ExecCommand.cs @@ -83,16 +83,19 @@ public void Execute() private static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionVariables variables, ILog log) { +#pragma warning disable CS0612 // Type or member is obsolete if (string.IsNullOrEmpty(args.Proj)) return false; args.Exec = "dotnet"; args.ExecArgs = $"msbuild \"{args.Proj}\" {args.ProjArgs}"; +#pragma warning restore CS0612 // Type or member is obsolete return RunExecCommandIfNeeded(args, workingDirectory, variables, log); } private static bool RunExecCommandIfNeeded(Arguments args, string workingDirectory, VersionVariables variables, ILog log) { +#pragma warning disable CS0612 // Type or member is obsolete if (string.IsNullOrEmpty(args.Exec)) return false; log.Info($"Launching {args.Exec} {args.ExecArgs}"); @@ -103,6 +106,7 @@ private static bool RunExecCommandIfNeeded(Arguments args, string workingDirecto if (results != 0) throw new WarningException($"Execution of {args.Exec} failed, non-zero return code"); +#pragma warning restore CS0612 // Type or member is obsolete return true; } diff --git a/src/GitVersionExe/GitVersionExecutor.cs b/src/GitVersionExe/GitVersionExecutor.cs index 36cb3503cd..ca13304687 100644 --- a/src/GitVersionExe/GitVersionExecutor.cs +++ b/src/GitVersionExe/GitVersionExecutor.cs @@ -76,7 +76,9 @@ private int VerifyArgumentsAndRun(Arguments arguments) arguments.Output.Add(OutputType.BuildServer); } +#pragma warning disable CS0612 // Type or member is obsolete if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec)) +#pragma warning restore CS0612 // Type or member is obsolete { arguments.Output.Add(OutputType.BuildServer); } @@ -118,18 +120,17 @@ private int VerifyArgumentsAndRun(Arguments arguments) } catch (WarningException exception) { - var error = $"An error occurred:\r\n{exception.Message}"; + var error = $"An error occurred:{System.Environment.NewLine}{exception.Message}"; log.Warning(error); return 1; } catch (Exception exception) { - var error = $"An unexpected error occurred:\r\n{exception}"; + var error = $"An unexpected error occurred:{System.Environment.NewLine}{exception}"; log.Error(error); if (arguments == null) return 1; - log.Info(string.Empty); log.Info("Attempting to show the current git graph (please include in issue): "); log.Info("Showing max of 100 commits"); diff --git a/src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj b/src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj index 9e565a0701..979e5d2b0b 100644 --- a/src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj +++ b/src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/GitVersionTask/MsBuildAppender.cs b/src/GitVersionTask/MsBuildAppender.cs index 946d5c144e..a6757ddce8 100644 --- a/src/GitVersionTask/MsBuildAppender.cs +++ b/src/GitVersionTask/MsBuildAppender.cs @@ -29,7 +29,7 @@ public void WriteTo(LogLevel level, string message) private void WriteLogEntry(LogLevel level, string str) { - var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}\r\n"; + var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}{System.Environment.NewLine}"; switch (level) { case LogLevel.None: