diff --git a/src/BenchmarkDotNet/Templates/R2RCsProj.txt b/src/BenchmarkDotNet/Templates/R2RCsProj.txt index e881418b1b..f47a825aa5 100644 --- a/src/BenchmarkDotNet/Templates/R2RCsProj.txt +++ b/src/BenchmarkDotNet/Templates/R2RCsProj.txt @@ -18,6 +18,8 @@ BenchmarkDotNet.Autogenerated.UniqueProgramName false + + $([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', 'o')) diff --git a/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs b/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs index 7ce4b32a5e..fe5aa36073 100644 --- a/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs +++ b/src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs @@ -135,7 +135,7 @@ protected override async ValueTask GenerateProjectAsync(BuildPartition buildPart await GenerateReflectionFileAsync(artifactsPaths, cancellationToken).ConfigureAwait(false); } - private string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger) => $""" + internal string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger) => $""" Exe @@ -159,6 +159,8 @@ private string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartiti false false false + + $([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', 'o')) {GetInstructionSetSettings(buildPartition)} {GetRuntimeSettings(buildPartition.RepresentativeBenchmarkCase.Job.Environment.Gc, buildPartition.Resolver)} diff --git a/tests/BenchmarkDotNet.Tests/AotProjectGeneratorTests.cs b/tests/BenchmarkDotNet.Tests/AotProjectGeneratorTests.cs new file mode 100644 index 0000000000..b36619250c --- /dev/null +++ b/tests/BenchmarkDotNet.Tests/AotProjectGeneratorTests.cs @@ -0,0 +1,66 @@ +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Helpers; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Loggers; +using BenchmarkDotNet.Parameters; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Tests.Mocks; +using BenchmarkDotNet.Toolchains; +using BenchmarkDotNet.Toolchains.NativeAot; +using System.Xml.Linq; + +namespace BenchmarkDotNet.Tests +{ + public class AotProjectGeneratorTests + { + private const string ExpectedIntermediateOutputPath = "$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', 'o'))"; + + [Fact] + public void NativeAotProjectUsesShortBuildPaths() + { + var config = ManualConfig.CreateEmpty().CreateImmutableConfig(); + var benchmark = BenchmarkCase.Create( + new Descriptor(MockFactory.MockType, MockFactory.MockMethodInfo), + Job.Default, + ParameterInstances.Empty, + config); + var buildPartition = new BuildPartition( + [new BenchmarkBuildInfo(benchmark, config, 0, new([]))], + BenchmarkRunnerClean.DefaultResolver); + var generator = new Generator( + ilCompilerVersion: "", + runtimeFrameworkVersion: "", + targetFrameworkMoniker: "net10.0", + cliPath: "", + runtimeIdentifier: "win-x64", + feeds: new Dictionary(), + useNuGetClearTag: false, + useTempFolderForRestore: false, + packagesRestorePath: "", + rootAllApplicationAssemblies: false, + ilcGenerateStackTraceData: true, + ilcOptimizationPreference: "Speed", + ilcInstructionSet: ""); + + string project = generator.GenerateProjectForNuGetBuild( + "Benchmarks.csproj", + buildPartition, + ArtifactsPaths.Empty, + NullLogger.Instance); + + AssertShortIntermediatePath(XDocument.Parse(project)); + } + + [Fact] + public void ReadyToRunProjectUsesShortBuildPaths() + { + AssertShortIntermediatePath(XDocument.Parse(ResourceHelper.LoadTemplate("R2RCsProj.txt"))); + } + + private static void AssertShortIntermediatePath(XDocument project) + { + Assert.Equal(ExpectedIntermediateOutputPath, project.Descendants("IntermediateOutputPath").Single().Value); + Assert.Empty(project.Descendants("BaseIntermediateOutputPath")); + } + } +}