diff --git a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
index 0d2f6f3e71..111e288a9f 100644
--- a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
+++ b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj
@@ -19,9 +19,7 @@
-
-
diff --git a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs
index 9ece53a3f5..f693649640 100644
--- a/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs
+++ b/src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.cs
@@ -285,7 +285,8 @@ public void NoWarnOnGitVersionYmlFile()
this.configurationProvider.ProvideForDirectory(this.repoPath);
- stringLogger.Length.ShouldBe(0);
+ var filePath = PathHelper.Combine(this.repoPath, ConfigurationFileLocator.DefaultFileName);
+ stringLogger.ShouldContain($"Found configuration file at '{filePath}'");
}
[Test]
diff --git a/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs b/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs
index 96db0f145c..6000db6c6c 100644
--- a/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs
+++ b/src/GitVersion.Configuration.Tests/Configuration/Extensions.cs
@@ -13,6 +13,12 @@ public static IDisposable SetupConfigFile(this IFileSystem fileSystem, s
}
var fullPath = PathHelper.Combine(path, fileName);
+ var directory = PathHelper.GetDirectoryName(fullPath);
+ if (!fileSystem.DirectoryExists(directory))
+ {
+ fileSystem.CreateDirectory(directory);
+ }
+
fileSystem.WriteAllText(fullPath, text);
return Disposable.Create(fullPath, () => fileSystem.Delete(fullPath));
diff --git a/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs b/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs
index e6410ceb26..755287a94d 100644
--- a/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs
+++ b/src/GitVersion.Core.Tests/Helpers/GitVersionCoreTestModule.cs
@@ -17,7 +17,7 @@ public void RegisterTypes(IServiceCollection services)
services.AddModule(new GitVersionConfigurationModule());
services.AddModule(new GitVersionCoreModule());
- services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
}
diff --git a/src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs b/src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs
deleted file mode 100644
index 06a4f74ee4..0000000000
--- a/src/GitVersion.Core.Tests/Helpers/TestFileSystem.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-using GitVersion.Helpers;
-
-namespace GitVersion.Core.Tests.Helpers;
-
-public class TestFileSystem : IFileSystem
-{
- private readonly Dictionary fileSystem = new(SysEnv.OSVersion.Platform == PlatformID.Unix ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase);
-
- public void Copy(string from, string to, bool overwrite)
- {
- var fromPath = Path.GetFullPath(from);
- var toPath = Path.GetFullPath(to);
- if (this.fileSystem.ContainsKey(toPath))
- {
- if (overwrite)
- this.fileSystem.Remove(toPath);
- else
- throw new IOException("File already exists");
- }
-
- if (!this.fileSystem.TryGetValue(fromPath, out var source))
- throw new FileNotFoundException($"The source file '{fromPath}' was not found", from);
-
- this.fileSystem.Add(toPath, source);
- }
-
- public void Move(string from, string to)
- {
- var fromPath = Path.GetFullPath(from);
- Copy(from, to, false);
- this.fileSystem.Remove(fromPath);
- }
-
- public bool Exists(string file)
- {
- var path = Path.GetFullPath(file);
- return this.fileSystem.ContainsKey(path);
- }
-
- public void Delete(string path)
- {
- var fullPath = Path.GetFullPath(path);
- this.fileSystem.Remove(fullPath);
- }
-
- public string ReadAllText(string path)
- {
- var fullPath = Path.GetFullPath(path);
- if (!this.fileSystem.TryGetValue(fullPath, out var content))
- throw new FileNotFoundException($"The file '{fullPath}' was not found", fullPath);
-
- var encoding = EncodingHelper.DetectEncoding(content) ?? Encoding.UTF8;
- return encoding.GetString(content);
- }
-
- public void WriteAllText(string? file, string fileContents)
- {
- var path = Path.GetFullPath(file ?? throw new ArgumentNullException(nameof(file)));
- var encoding = fileSystem.TryGetValue(path, out var value) ? EncodingHelper.DetectEncoding(value) ?? Encoding.UTF8
- : Encoding.UTF8;
- WriteAllText(path, fileContents, encoding);
- }
-
- public void WriteAllText(string? file, string fileContents, Encoding encoding)
- {
- var path = Path.GetFullPath(file ?? throw new ArgumentNullException(nameof(file)));
- this.fileSystem[path] = encoding.GetBytes(fileContents);
- }
-
- public IEnumerable DirectoryEnumerateFiles(string? directory, string searchPattern, SearchOption searchOption) => throw new NotImplementedException();
-
- public Stream OpenWrite(string path) => new TestStream(path, this);
-
- public Stream OpenRead(string path)
- {
- var fullPath = Path.GetFullPath(path);
- if (!this.fileSystem.TryGetValue(fullPath, out var content))
- throw new FileNotFoundException("File not found.", fullPath);
-
- return new MemoryStream(content);
- }
-
- public void CreateDirectory(string path)
- {
- var fullPath = Path.GetFullPath(path);
- this.fileSystem[fullPath] = [];
- }
-
- public bool DirectoryExists(string path)
- {
- var fullPath = Path.GetFullPath(path);
- return this.fileSystem.ContainsKey(fullPath);
- }
-
- public long GetLastDirectoryWrite(string path) => 1;
-}
diff --git a/src/GitVersion.Core.Tests/Helpers/TestStream.cs b/src/GitVersion.Core.Tests/Helpers/TestStream.cs
deleted file mode 100644
index 836a45474f..0000000000
--- a/src/GitVersion.Core.Tests/Helpers/TestStream.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-namespace GitVersion.Core.Tests.Helpers;
-
-public class TestStream(string path, IFileSystem testFileSystem) : Stream
-{
- private readonly MemoryStream underlying = new();
-
- protected override void Dispose(bool disposing)
- {
- Flush();
- base.Dispose(disposing);
- }
-
- public override void Flush()
- {
- this.underlying.Position = 0;
- var readToEnd = new StreamReader(this.underlying).ReadToEnd();
- testFileSystem.WriteAllText(path, readToEnd);
- }
-
- public override long Seek(long offset, SeekOrigin origin) => this.underlying.Seek(offset, origin);
-
- public override void SetLength(long value) => this.underlying.SetLength(value);
-
- public override int Read(byte[] buffer, int offset, int count) => this.underlying.Read(buffer, offset, count);
-
- public override void Write(byte[] buffer, int offset, int count) => this.underlying.Write(buffer, offset, count);
-
- public override bool CanRead => this.underlying.CanRead;
- public override bool CanSeek => this.underlying.CanSeek;
- public override bool CanWrite => this.underlying.CanWrite;
- public override long Length => this.underlying.Length;
-
- public override long Position
- {
- get => this.underlying.Position;
- set => this.underlying.Position = value;
- }
-}
diff --git a/src/GitVersion.Core/Helpers/PathHelper.cs b/src/GitVersion.Core/Helpers/PathHelper.cs
index b89918ed75..761aa307b9 100644
--- a/src/GitVersion.Core/Helpers/PathHelper.cs
+++ b/src/GitVersion.Core/Helpers/PathHelper.cs
@@ -26,6 +26,13 @@ public static string GetTempPath()
public static string GetRepositoryTempPath() => Combine(GetTempPath(), "TestRepositories", Guid.NewGuid().ToString());
+ public static string GetDirectoryName(string? path)
+ {
+ ArgumentNullException.ThrowIfNull(path, nameof(path));
+
+ return Path.GetDirectoryName(path)!;
+ }
+
public static string GetFullPath(string? path)
{
ArgumentNullException.ThrowIfNull(path, nameof(path));
diff --git a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs
index f2cd6919a1..c24047a798 100644
--- a/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs
+++ b/src/GitVersion.Core/VersionCalculation/Caching/GitVersionCacheKeyFactory.cs
@@ -118,7 +118,7 @@ private List CalculateDirectoryContents(string root)
{
var fi = new FileInfo(file);
result.Add(fi.Name);
- result.Add(File.ReadAllText(file));
+ result.Add(this.fileSystem.ReadAllText(file));
}
catch (IOException e)
{
diff --git a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj
index b7677e977d..428b5be4a2 100644
--- a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj
+++ b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj
@@ -31,9 +31,7 @@
-
-
diff --git a/src/GitVersion.Output.Tests/Output/WixFileTests.cs b/src/GitVersion.Output.Tests/Output/WixFileTests.cs
index 4d41fec15b..ebd91284f2 100644
--- a/src/GitVersion.Output.Tests/Output/WixFileTests.cs
+++ b/src/GitVersion.Output.Tests/Output/WixFileTests.cs
@@ -95,6 +95,10 @@ public void UpdateWixVersionFileWhenFileAlreadyExists()
// fake an already existing file
var file = PathHelper.Combine(workingDir, WixVersionFileUpdater.WixVersionFileName);
+ if (!fileSystem.DirectoryExists(workingDir))
+ {
+ fileSystem.CreateDirectory(workingDir);
+ }
fileSystem.WriteAllText(file, new('x', 1024 * 1024));
wixVersionFileUpdater.Execute(versionVariables, new(workingDir));
diff --git a/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs b/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs
index 3d2dfe0104..4f76e347ac 100644
--- a/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs
+++ b/src/GitVersion.Output/WixUpdater/WixVersionFileUpdater.cs
@@ -25,7 +25,15 @@ public void Execute(GitVersionVariables variables, WixVersionContext context)
var root = doc.DocumentElement;
doc.InsertBefore(xmlDecl, root);
- this.fileSystem.Delete(this.wixVersionFile);
+ if (this.fileSystem.Exists(this.wixVersionFile))
+ {
+ this.fileSystem.Delete(this.wixVersionFile);
+ }
+
+ if (!this.fileSystem.DirectoryExists(context.WorkingDirectory))
+ {
+ this.fileSystem.CreateDirectory(context.WorkingDirectory);
+ }
using var fs = this.fileSystem.OpenWrite(this.wixVersionFile);
doc.Save(fs);
}
diff --git a/src/GitVersion.sln.DotSettings b/src/GitVersion.sln.DotSettings
index 9d9eae6664..970fd59ec8 100644
--- a/src/GitVersion.sln.DotSettings
+++ b/src/GitVersion.sln.DotSettings
@@ -707,16 +707,11 @@ II.2.12 <HandlesEvent />
True
True
True
-
-
- True
+ True
False
-
-
-
-
- <data />
+ <data />
<data><IncludeFilters /><ExcludeFilters /></data>
True
True
- True
+ True
+ True