Skip to content

Commit 0a734a9

Browse files
feat: set RuntimeHostConfigurationOption on generated project (#2453)
* test: RuntimeHostConfigurationOptionIsCopied * feat: set RuntimeHostConfigurationOption on generated project
1 parent e170684 commit 0a734a9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public class CsProjGenerator : DotNetCliGenerator, IEquatable<CsProjGenerator>
3434
"CopyLocalLockFileAssemblies",
3535
"PreserveCompilationContext",
3636
"UserSecretsId",
37-
"EnablePreviewFeatures"
37+
"EnablePreviewFeatures",
38+
"RuntimeHostConfigurationOption",
3839
}.ToImmutableArray();
3940

4041
public string RuntimeFrameworkVersion { get; }

tests/BenchmarkDotNet.Tests/CsProjGeneratorTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace BenchmarkDotNet.Tests
1818
public class CsProjGeneratorTests
1919
{
2020
private FileInfo TestAssemblyFileInfo = new FileInfo(typeof(CsProjGeneratorTests).Assembly.Location);
21+
private const string runtimeHostConfigurationOptionChunk = """
22+
<ItemGroup>
23+
<RuntimeHostConfigurationOption Include="System.Runtime.Loader.UseRidGraph" Value="true" />
24+
</ItemGroup>
25+
""";
2126

2227
[Theory]
2328
[InlineData("net471", false)]
@@ -68,7 +73,7 @@ private void AssertParsedSdkName(string csProjContent, string targetFrameworkMon
6873

6974
private static void AssertCustomProperties(string expected, string actual)
7075
{
71-
Assert.Equal(expected.Replace(Environment.NewLine, "\n").Replace("\n", Environment.NewLine), actual);
76+
Assert.Equal(expected.Replace("\r", "").Replace("\n", Environment.NewLine), actual);
7277
}
7378

7479
[Fact]
@@ -158,6 +163,24 @@ public void SettingsFromPropsFileImportedUsingRelativePathGetCopies()
158163
File.Delete(propsFilePath);
159164
}
160165

166+
[Fact]
167+
public void RuntimeHostConfigurationOptionIsCopied()
168+
{
169+
string source = $@"
170+
<Project Sdk=""Microsoft.NET.Sdk"">
171+
{runtimeHostConfigurationOptionChunk}
172+
</Project>";
173+
174+
var sut = new CsProjGenerator("netcoreapp3.0", null, null, null, true);
175+
176+
var xmlDoc = new XmlDocument();
177+
xmlDoc.LoadXml(source);
178+
var (customProperties, sdkName) = sut.GetSettingsThatNeedToBeCopied(xmlDoc, TestAssemblyFileInfo);
179+
180+
AssertCustomProperties(runtimeHostConfigurationOptionChunk, customProperties);
181+
Assert.Equal("Microsoft.NET.Sdk", sdkName);
182+
}
183+
161184
[Fact]
162185
public void TheDefaultFilePathShouldBeUsedWhenAnAssemblyLocationIsEmpty()
163186
{

0 commit comments

Comments
 (0)