Skip to content

Commit

Permalink
feat: set RuntimeHostConfigurationOption on generated project (#2453)
Browse files Browse the repository at this point in the history
* test: RuntimeHostConfigurationOptionIsCopied

* feat: set RuntimeHostConfigurationOption on generated project
  • Loading branch information
workgroupengineering authored Oct 27, 2023
1 parent e170684 commit 0a734a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class CsProjGenerator : DotNetCliGenerator, IEquatable<CsProjGenerator>
"CopyLocalLockFileAssemblies",
"PreserveCompilationContext",
"UserSecretsId",
"EnablePreviewFeatures"
"EnablePreviewFeatures",
"RuntimeHostConfigurationOption",
}.ToImmutableArray();

public string RuntimeFrameworkVersion { get; }
Expand Down
25 changes: 24 additions & 1 deletion tests/BenchmarkDotNet.Tests/CsProjGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace BenchmarkDotNet.Tests
public class CsProjGeneratorTests
{
private FileInfo TestAssemblyFileInfo = new FileInfo(typeof(CsProjGeneratorTests).Assembly.Location);
private const string runtimeHostConfigurationOptionChunk = """
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Runtime.Loader.UseRidGraph" Value="true" />
</ItemGroup>
""";

[Theory]
[InlineData("net471", false)]
Expand Down Expand Up @@ -68,7 +73,7 @@ private void AssertParsedSdkName(string csProjContent, string targetFrameworkMon

private static void AssertCustomProperties(string expected, string actual)
{
Assert.Equal(expected.Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine), actual);
Assert.Equal(expected.Replace("\r", "").Replace("\n", Environment.NewLine), actual);
}

[Fact]
Expand Down Expand Up @@ -158,6 +163,24 @@ public void SettingsFromPropsFileImportedUsingRelativePathGetCopies()
File.Delete(propsFilePath);
}

[Fact]
public void RuntimeHostConfigurationOptionIsCopied()
{
string source = $@"
<Project Sdk=""Microsoft.NET.Sdk"">
{runtimeHostConfigurationOptionChunk}
</Project>";

var sut = new CsProjGenerator("netcoreapp3.0", null, null, null, true);

var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(source);
var (customProperties, sdkName) = sut.GetSettingsThatNeedToBeCopied(xmlDoc, TestAssemblyFileInfo);

AssertCustomProperties(runtimeHostConfigurationOptionChunk, customProperties);
Assert.Equal("Microsoft.NET.Sdk", sdkName);
}

[Fact]
public void TheDefaultFilePathShouldBeUsedWhenAnAssemblyLocationIsEmpty()
{
Expand Down

0 comments on commit 0a734a9

Please sign in to comment.