diff --git a/new-cli/GitVersion.Common/GitVersion.Common.csproj b/new-cli/GitVersion.Common/GitVersion.Common.csproj
index f2507e4fbd..a8d47b764c 100644
--- a/new-cli/GitVersion.Common/GitVersion.Common.csproj
+++ b/new-cli/GitVersion.Common/GitVersion.Common.csproj
@@ -3,64 +3,64 @@
-
+
Git\AuthenticationInfo.cs
-
+
Git\CommitFilter.cs
-
+
Git\IBranch.cs
-
+
Git\IBranchCollection.cs
-
+
Git\ICommit.cs
-
+
Git\ICommitCollection.cs
-
+
Git\IGitObject.cs
-
+
Git\IGitRepository.cs
-
+
Git\INamedReference.cs
-
+
Git\IObjectId.cs
-
+
Git\IReference.cs
-
+
Git\IReferenceCollection.cs
-
+
Git\IRefSpec.cs
-
+
Git\IRefSpecCollection.cs
-
+
Git\IRemote.cs
-
+
Git\IRemoteCollection.cs
-
+
Git\ITag.cs
-
+
Git\ITagCollection.cs
-
+
Git\ReferenceName.cs
-
+
Git\RefSpecDirection.cs
diff --git a/src/GitVersion.Core/Agents/BuildAgentBase.cs b/src/GitVersion.Abstractions/Agents/BuildAgentBase.cs
similarity index 95%
rename from src/GitVersion.Core/Agents/BuildAgentBase.cs
rename to src/GitVersion.Abstractions/Agents/BuildAgentBase.cs
index e3b572a942..5d20668153 100644
--- a/src/GitVersion.Core/Agents/BuildAgentBase.cs
+++ b/src/GitVersion.Abstractions/Agents/BuildAgentBase.cs
@@ -7,12 +7,12 @@ namespace GitVersion.Agents;
public abstract class BuildAgentBase : ICurrentBuildAgent
{
protected readonly ILog Log;
- protected IEnvironment Environment { get; }
+ protected IEnvironment Environment;
protected BuildAgentBase(IEnvironment environment, ILog log)
{
this.Log = log;
- Environment = environment;
+ this.Environment = environment;
}
protected abstract string EnvironmentVariable { get; }
diff --git a/src/GitVersion.Abstractions/Common/IGitVersionModule.cs b/src/GitVersion.Abstractions/Common/IGitVersionModule.cs
index e1461d9fc2..0d8e217a35 100644
--- a/src/GitVersion.Abstractions/Common/IGitVersionModule.cs
+++ b/src/GitVersion.Abstractions/Common/IGitVersionModule.cs
@@ -1,3 +1,4 @@
+using GitVersion.Extensions;
using Microsoft.Extensions.DependencyInjection;
namespace GitVersion;
@@ -5,4 +6,12 @@ namespace GitVersion;
public interface IGitVersionModule
{
void RegisterTypes(IServiceCollection services);
+
+ static IEnumerable FindAllDerivedTypes(Assembly? assembly)
+ {
+ assembly.NotNull();
+
+ var derivedType = typeof(T);
+ return assembly.GetTypes().Where(t => t != derivedType && derivedType.IsAssignableFrom(t));
+ }
}
diff --git a/src/GitVersion.Core/Logging/LogAction.cs b/src/GitVersion.Abstractions/Common/Models/LogAction.cs
similarity index 100%
rename from src/GitVersion.Core/Logging/LogAction.cs
rename to src/GitVersion.Abstractions/Common/Models/LogAction.cs
diff --git a/src/GitVersion.Core/Logging/Disposable.cs b/src/GitVersion.Abstractions/Extensions/Disposable.cs
similarity index 100%
rename from src/GitVersion.Core/Logging/Disposable.cs
rename to src/GitVersion.Abstractions/Extensions/Disposable.cs
diff --git a/src/GitVersion.Abstractions/Extensions/GitVersionVariablesExtensions.cs b/src/GitVersion.Abstractions/Extensions/GitVersionVariablesExtensions.cs
new file mode 100644
index 0000000000..402a2de16f
--- /dev/null
+++ b/src/GitVersion.Abstractions/Extensions/GitVersionVariablesExtensions.cs
@@ -0,0 +1,52 @@
+using System.Text.Encodings.Web;
+using GitVersion.OutputVariables;
+
+namespace GitVersion.Extensions;
+
+public static class GitVersionVariablesExtensions
+{
+ public static string ToJsonString(this GitVersionVariables gitVersionVariables)
+ {
+ var variablesType = typeof(VersionVariablesJsonModel);
+ var variables = new VersionVariablesJsonModel();
+
+ foreach (var (key, value) in gitVersionVariables.OrderBy(x => x.Key))
+ {
+ var propertyInfo = variablesType.GetProperty(key);
+ propertyInfo?.SetValue(variables, ChangeType(value, propertyInfo.PropertyType));
+ }
+
+ var serializeOptions = GetJsonSerializerOptions();
+
+ return JsonSerializer.Serialize(variables, serializeOptions);
+ }
+
+ public static JsonSerializerOptions GetJsonSerializerOptions()
+ {
+ var serializeOptions = new JsonSerializerOptions
+ {
+ WriteIndented = true,
+ Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
+ Converters =
+ {
+ new VersionVariablesJsonStringConverter()
+ }
+ };
+ return serializeOptions;
+ }
+
+ private static object? ChangeType(object? value, Type type)
+ {
+ if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
+ {
+ if (value == null || value.ToString()?.Length == 0)
+ {
+ return null;
+ }
+
+ type = Nullable.GetUnderlyingType(type)!;
+ }
+
+ return Convert.ChangeType(value, type);
+ }
+}
diff --git a/src/GitVersion.Core/Logging/LogExtensions.cs b/src/GitVersion.Abstractions/Extensions/LogExtensions.cs
similarity index 100%
rename from src/GitVersion.Core/Logging/LogExtensions.cs
rename to src/GitVersion.Abstractions/Extensions/LogExtensions.cs
diff --git a/src/GitVersion.Core/Extensions/ReadEmbeddedResourceExtensions.cs b/src/GitVersion.Abstractions/Extensions/ReadEmbeddedResourceExtensions.cs
similarity index 100%
rename from src/GitVersion.Core/Extensions/ReadEmbeddedResourceExtensions.cs
rename to src/GitVersion.Abstractions/Extensions/ReadEmbeddedResourceExtensions.cs
diff --git a/src/GitVersion.Abstractions/GitVersion.Abstractions.csproj b/src/GitVersion.Abstractions/GitVersion.Abstractions.csproj
index cb02a597d7..da0548d063 100644
--- a/src/GitVersion.Abstractions/GitVersion.Abstractions.csproj
+++ b/src/GitVersion.Abstractions/GitVersion.Abstractions.csproj
@@ -10,6 +10,7 @@
+
diff --git a/src/GitVersion.Core/Helpers/PathHelper.cs b/src/GitVersion.Abstractions/Helpers/PathHelper.cs
similarity index 100%
rename from src/GitVersion.Core/Helpers/PathHelper.cs
rename to src/GitVersion.Abstractions/Helpers/PathHelper.cs
diff --git a/src/GitVersion.Core/OutputVariables/VersionVariablesJsonModel.cs b/src/GitVersion.Abstractions/Output/VersionVariablesJsonModel.cs
similarity index 100%
rename from src/GitVersion.Core/OutputVariables/VersionVariablesJsonModel.cs
rename to src/GitVersion.Abstractions/Output/VersionVariablesJsonModel.cs
diff --git a/src/GitVersion.Core/OutputVariables/VersionVariablesJsonStringConverter.cs b/src/GitVersion.Abstractions/Output/VersionVariablesJsonStringConverter.cs
similarity index 100%
rename from src/GitVersion.Core/OutputVariables/VersionVariablesJsonStringConverter.cs
rename to src/GitVersion.Abstractions/Output/VersionVariablesJsonStringConverter.cs
diff --git a/src/GitVersion.BuildAgents/GitVersion.BuildAgents.csproj b/src/GitVersion.BuildAgents/GitVersion.BuildAgents.csproj
index 3c0a2f6225..cb33a82c90 100644
--- a/src/GitVersion.BuildAgents/GitVersion.BuildAgents.csproj
+++ b/src/GitVersion.BuildAgents/GitVersion.BuildAgents.csproj
@@ -1,6 +1,6 @@
-
+
diff --git a/src/GitVersion.BuildAgents/GitVersionBuildAgentsModule.cs b/src/GitVersion.BuildAgents/GitVersionBuildAgentsModule.cs
index 171fed7bb4..17ba4b85b8 100644
--- a/src/GitVersion.BuildAgents/GitVersionBuildAgentsModule.cs
+++ b/src/GitVersion.BuildAgents/GitVersionBuildAgentsModule.cs
@@ -2,11 +2,11 @@
namespace GitVersion.Agents;
-public class GitVersionBuildAgentsModule : GitVersionModule
+public class GitVersionBuildAgentsModule : IGitVersionModule
{
- public override void RegisterTypes(IServiceCollection services)
+ public void RegisterTypes(IServiceCollection services)
{
- var buildAgents = FindAllDerivedTypes(Assembly.GetAssembly(GetType()));
+ var buildAgents = IGitVersionModule.FindAllDerivedTypes(Assembly.GetAssembly(GetType()));
foreach (var buildAgent in buildAgents)
{
diff --git a/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs
index de0f59334a..59b7c1fc4d 100644
--- a/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs
+++ b/src/GitVersion.Core.Tests/VersionCalculation/JsonVersionBuilderTests.cs
@@ -1,5 +1,5 @@
using GitVersion.Core.Tests.Helpers;
-using GitVersion.OutputVariables;
+using GitVersion.Extensions;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;
diff --git a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs
index 2306d62f38..07e9d2f399 100644
--- a/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs
+++ b/src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs
@@ -1,6 +1,6 @@
using GitVersion.Core.Tests.Helpers;
+using GitVersion.Extensions;
using GitVersion.Logging;
-using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using Microsoft.Extensions.DependencyInjection;
diff --git a/src/GitVersion.Core/Configuration/Init/GitVersionInitModule.cs b/src/GitVersion.Core/Configuration/Init/GitVersionInitModule.cs
index 156fca30c7..048d81c233 100644
--- a/src/GitVersion.Core/Configuration/Init/GitVersionInitModule.cs
+++ b/src/GitVersion.Core/Configuration/Init/GitVersionInitModule.cs
@@ -3,14 +3,14 @@
namespace GitVersion.Configuration.Init;
-public class GitVersionInitModule : GitVersionModule
+public class GitVersionInitModule : IGitVersionModule
{
- public override void RegisterTypes(IServiceCollection services)
+ public void RegisterTypes(IServiceCollection services)
{
services.AddTransient();
services.AddTransient();
- var steps = FindAllDerivedTypes(Assembly.GetAssembly(GetType()));
+ var steps = IGitVersionModule.FindAllDerivedTypes(Assembly.GetAssembly(GetType()));
foreach (var step in steps)
{
diff --git a/src/GitVersion.Core/Core/GitVersionModule.cs b/src/GitVersion.Core/Core/GitVersionModule.cs
deleted file mode 100644
index f9b24a65e0..0000000000
--- a/src/GitVersion.Core/Core/GitVersionModule.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using GitVersion.Extensions;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace GitVersion;
-
-public abstract class GitVersionModule : IGitVersionModule
-{
- public abstract void RegisterTypes(IServiceCollection services);
-
- protected static IEnumerable FindAllDerivedTypes(Assembly? assembly)
- {
- assembly.NotNull();
-
- var derivedType = typeof(T);
- return assembly.GetTypes().Where(t => t != derivedType && derivedType.IsAssignableFrom(t));
- }
-}
diff --git a/src/GitVersion.Core/OutputVariables/VersionVariablesHelper.cs b/src/GitVersion.Core/Helpers/VersionVariablesHelper.cs
similarity index 58%
rename from src/GitVersion.Core/OutputVariables/VersionVariablesHelper.cs
rename to src/GitVersion.Core/Helpers/VersionVariablesHelper.cs
index 5a41df3a74..e66f26819f 100644
--- a/src/GitVersion.Core/OutputVariables/VersionVariablesHelper.cs
+++ b/src/GitVersion.Core/Helpers/VersionVariablesHelper.cs
@@ -1,4 +1,3 @@
-using System.Text.Encodings.Web;
using GitVersion.Extensions;
using GitVersion.Helpers;
using YamlDotNet.Serialization;
@@ -9,7 +8,7 @@ public static class VersionVariablesHelper
{
public static GitVersionVariables FromJson(string json)
{
- var serializeOptions = JsonSerializerOptions();
+ var serializeOptions = GitVersionVariablesExtensions.GetJsonSerializerOptions();
var variablePairs = JsonSerializer.Deserialize>(json, serializeOptions);
return FromDictionary(variablePairs);
}
@@ -33,22 +32,6 @@ public static GitVersionVariables FromFile(string filePath, IFileSystem fileSyst
}
}
- public static string ToJsonString(this GitVersionVariables gitVersionVariables)
- {
- var variablesType = typeof(VersionVariablesJsonModel);
- var variables = new VersionVariablesJsonModel();
-
- foreach (var (key, value) in gitVersionVariables.OrderBy(x => x.Key))
- {
- var propertyInfo = variablesType.GetProperty(key);
- propertyInfo?.SetValue(variables, ChangeType(value, propertyInfo.PropertyType));
- }
-
- var serializeOptions = JsonSerializerOptions();
-
- return JsonSerializer.Serialize(variables, serializeOptions);
- }
-
private static GitVersionVariables FromDictionary(IEnumerable>? properties)
{
var type = typeof(GitVersionVariables);
@@ -71,25 +54,4 @@ private static GitVersionVariables FromFileInternal(string filePath, IFileSystem
var versionVariables = FromDictionary(dictionary);
return versionVariables;
}
-
- private static JsonSerializerOptions JsonSerializerOptions()
- {
- var serializeOptions = new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Converters = { new VersionVariablesJsonStringConverter() } };
- return serializeOptions;
- }
-
- private static object? ChangeType(object? value, Type type)
- {
- if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
- {
- if (value == null || value.ToString()?.Length == 0)
- {
- return null;
- }
-
- type = Nullable.GetUnderlyingType(type)!;
- }
-
- return Convert.ChangeType(value, type);
- }
}
diff --git a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs
index 1721e51100..23d0580365 100644
--- a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs
+++ b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs
@@ -2,11 +2,11 @@
namespace GitVersion.VersionCalculation;
-public class VersionStrategyModule : GitVersionModule
+public class VersionStrategyModule : IGitVersionModule
{
- public override void RegisterTypes(IServiceCollection services)
+ public void RegisterTypes(IServiceCollection services)
{
- var versionStrategies = FindAllDerivedTypes(Assembly.GetAssembly(GetType()))
+ var versionStrategies = IGitVersionModule.FindAllDerivedTypes(Assembly.GetAssembly(GetType()))
.Where(x => x is { IsAbstract: false, IsInterface: false });
foreach (var versionStrategy in versionStrategies)
diff --git a/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs b/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs
index 8eb35ecc5f..494db200c3 100644
--- a/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/GitRepository.extended.cs
@@ -92,7 +92,7 @@ private DirectReference GetPullRequestReference(AuthenticationInfo auth, LibGit2
: network.ListReferences(remote))
.Select(r => r.ResolveToDirectReference()).ToList();
- this.log.Info($"Remote Refs:{System.Environment.NewLine}" + string.Join(System.Environment.NewLine, remoteTips.Select(r => r.CanonicalName)));
+ this.log.Info($"Remote Refs:{Environment.NewLine}" + string.Join(Environment.NewLine, remoteTips.Select(r => r.CanonicalName)));
var refs = remoteTips.Where(r => r.TargetIdentifier == headTipSha).ToList();
switch (refs.Count)
diff --git a/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj b/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj
index b291454cae..e4341c50ec 100644
--- a/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj
+++ b/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj
@@ -5,7 +5,7 @@
-
+
diff --git a/src/GitVersion.Output/GitVersion.Output.csproj b/src/GitVersion.Output/GitVersion.Output.csproj
index cba67d4847..f4d4a65785 100644
--- a/src/GitVersion.Output/GitVersion.Output.csproj
+++ b/src/GitVersion.Output/GitVersion.Output.csproj
@@ -1,6 +1,6 @@
-
+
diff --git a/src/GitVersion.Output/GitVersionInfo/GitVersionInfoGenerator.cs b/src/GitVersion.Output/GitVersionInfo/GitVersionInfoGenerator.cs
index 487e579a72..ec27c0a316 100644
--- a/src/GitVersion.Output/GitVersionInfo/GitVersionInfoGenerator.cs
+++ b/src/GitVersion.Output/GitVersionInfo/GitVersionInfoGenerator.cs
@@ -42,7 +42,7 @@ public void Execute(GitVersionVariables variables, GitVersionInfoContext context
var indentation = GetIndentation(fileExtension);
var lines = variables.OrderBy(x => x.Key).Select(v => string.Format(indentation + addFormat, v.Key, v.Value));
- var members = string.Join(System.Environment.NewLine, lines);
+ var members = string.Join(Environment.NewLine, lines);
var fileContents = string.Format(template, members);