diff --git a/Directory.Build.props b/Directory.Build.props index 1212b92c88..1649808ac5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,6 +4,7 @@ net8.0 true embedded + $(MSBuildThisFileDirectory)artifacts enable enable 0.0.1-dev diff --git a/docs/prebuild.ts b/docs/prebuild.ts index d1ba454319..1c3b2903fc 100644 --- a/docs/prebuild.ts +++ b/docs/prebuild.ts @@ -19,7 +19,7 @@ async function emptyDirectory(dir: string): Promise { async function buildApiDocs(): Promise { const targetDir = './docs/api'; const dll = - '../src/Riok.Mapperly.Abstractions/bin/Debug/netstandard2.0/Riok.Mapperly.Abstractions.dll'; + '../artifacts/bin/Riok.Mapperly.Abstractions/debug/Riok.Mapperly.Abstractions.dll'; // clean target directory await emptyDirectory(targetDir); @@ -91,17 +91,14 @@ async function buildSamples(): Promise { const targetDir = join(generatedDataDir, 'samples'); await mkdir(targetDir); - const sampleProject = '../samples/Riok.Mapperly.Sample'; - const projectFilesToCopy = ['CarMapper.cs', 'Car.cs', 'CarDto.cs']; - const generatedMapperFile = join( - sampleProject, - 'obj/Debug/net8.0/generated/Riok.Mapperly/Riok.Mapperly.MapperGenerator/CarMapper.g.cs', - ); - // Copy generated mapper to target dir + const generatedMapperFile = + '../artifacts/obj/Riok.Mapperly.Sample/debug/generated/Riok.Mapperly/Riok.Mapperly.MapperGenerator/CarMapper.g.cs'; await copyFile(generatedMapperFile, join(targetDir, 'CarMapper.g.cs')); // Copy sample project files to target dir + const sampleProject = '../samples/Riok.Mapperly.Sample'; + const projectFilesToCopy = ['CarMapper.cs', 'Car.cs', 'CarDto.cs']; for (const file of projectFilesToCopy) { await copyFile(join(sampleProject, file), join(targetDir, file)); } diff --git a/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs b/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs index 58d797b1e1..e371b3124a 100644 --- a/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs +++ b/test/Riok.Mapperly.IntegrationTests/BaseMapperTest.cs @@ -15,6 +15,9 @@ namespace Riok.Mapperly.IntegrationTests { public abstract class BaseMapperTest { + private static string SolutionDirectory = GetSolutionDirectory(); + private static string ProjectDirectory = GetProjectDirectory(); + static BaseMapperTest() { #if !NET6_0_OR_GREATER @@ -28,21 +31,24 @@ static BaseMapperTest() VerifierSettings.DontScrubDateTimes(); Verifier.DerivePathInfo( - (file, _, type, method) => + (_, _, type, method) => new PathInfo( - Path.Combine(Path.GetDirectoryName(file)!, "_snapshots"), + Path.Combine(ProjectDirectory, "_snapshots"), type.Name, method.Name + GetSnapshotVersionSuffix(type, method) ) ); } - protected string GetGeneratedMapperFilePath(string name, [CallerFilePath] string filePath = "") + protected string GetGeneratedMapperFilePath(string name) { return Path.Combine( - Path.GetDirectoryName(filePath)!, + SolutionDirectory, + "artifacts", "obj", - "GeneratedFiles", + "Riok.Mapperly.IntegrationTests", + "debug", + "generated", "Riok.Mapperly", "Riok.Mapperly.MapperGenerator", name + ".g.cs" @@ -169,5 +175,26 @@ private static Versions GetCurrentVersion() throw new InvalidOperationException("Target framework is not supported"); #endif } + + private static string GetProjectDirectory() => FindDirectoryOfFile(".csproj"); + + private static string GetSolutionDirectory() => FindDirectoryOfFile(".sln"); + + private static string FindDirectoryOfFile(string fileExtension, [CallerFilePath] string baseFilePath = "") + { + var dir = + Path.GetDirectoryName(baseFilePath) ?? throw new InvalidOperationException($"Could not get directory from {baseFilePath}"); + + while (Directory.GetFiles(dir, "*" + fileExtension, SearchOption.TopDirectoryOnly).Length == 0) + { + dir = Path.GetDirectoryName(dir); + if (dir == null) + { + throw new InvalidOperationException($"Could not find directory from file {baseFilePath}"); + } + } + + return dir; + } } } diff --git a/test/Riok.Mapperly.IntegrationTests/Riok.Mapperly.IntegrationTests.csproj b/test/Riok.Mapperly.IntegrationTests/Riok.Mapperly.IntegrationTests.csproj index 415290ea2c..36fc498c5c 100644 --- a/test/Riok.Mapperly.IntegrationTests/Riok.Mapperly.IntegrationTests.csproj +++ b/test/Riok.Mapperly.IntegrationTests/Riok.Mapperly.IntegrationTests.csproj @@ -6,13 +6,10 @@ $(MapperlyIntegrationTestsTargetFramework) true - $(BaseIntermediateOutputPath)/GeneratedFiles disable - preview - 9.0