Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set RuntimeHostConfigurationOption on generated project #2453

Merged
merged 2 commits into from Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs
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
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