diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs
index f829e630bc29..26d087b822b5 100644
--- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs
+++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs
@@ -578,7 +578,11 @@ protected void WithRetry(Action action)
/// Creates a file provider.
///
/// The file provider.
- public IFileProvider Create() => new PhysicalFileProvider(_rootPath);
+ public IFileProvider Create()
+ {
+ Directory.CreateDirectory(_rootPath);
+ return new PhysicalFileProvider(_rootPath);
+ }
#endregion
}
diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/IO/PhysicalFileSystemTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/IO/PhysicalFileSystemTests.cs
index 7893c8a6f629..2476f69c0429 100644
--- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/IO/PhysicalFileSystemTests.cs
+++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/IO/PhysicalFileSystemTests.cs
@@ -2,6 +2,7 @@
// See LICENSE for more details.
using System.Text;
+using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
@@ -103,4 +104,32 @@ public void GetFullPathTest()
// that path is invalid as it would be outside the root directory
Assert.Throws(() => _fileSystem.GetFullPath("../../foo.tmp"));
}
+
+ [Test]
+ public void CreateFileProviderCreatesDirectoryIfMissing()
+ {
+ var nonExistentPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests", "NonExistent");
+ if (Directory.Exists(nonExistentPath))
+ {
+ Directory.Delete(nonExistentPath, true);
+ }
+
+ var fs = new PhysicalFileSystem(
+ TestHelper.IOHelper,
+ TestHelper.GetHostingEnvironment(),
+ Mock.Of>(),
+ nonExistentPath,
+ "/Media/");
+
+ IFileProvider fileProvider = ((IFileProviderFactory)fs).Create();
+ try
+ {
+ Assert.IsNotNull(fileProvider);
+ Assert.IsTrue(Directory.Exists(nonExistentPath));
+ }
+ finally
+ {
+ (fileProvider as IDisposable)?.Dispose();
+ }
+ }
}