Skip to content

Commit df02314

Browse files
committed
Fix #2581: Copy WarningsAsErrors setting to generated project
Add WarningsAsErrors to SettingsWeWantToCopy array in CsProjGenerator so that NuGet restore warnings configured in the source project are preserved in the generated benchmark project and fail the build. Added test WarningsAsErrorsSettingGetsCopied() to verify the fix.
1 parent a3b4236 commit df02314

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class CsProjGenerator : DotNetCliGenerator, IEquatable<CsProjGenerator>
3838
"UserSecretsId",
3939
"EnablePreviewFeatures",
4040
"RuntimeHostConfigurationOption",
41+
"WarningsAsErrors",
4142
}.ToImmutableArray();
4243

4344
public string RuntimeFrameworkVersion { get; }

tests/BenchmarkDotNet.Tests/CsProjGeneratorTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ public void RuntimeHostConfigurationOptionIsCopied()
181181
Assert.Equal("Microsoft.NET.Sdk", sdkName);
182182
}
183183

184+
[Fact]
185+
public void WarningsAsErrorsSettingGetsCopied()
186+
{
187+
const string withWarningsAsErrors = @"
188+
<Project Sdk=""Microsoft.NET.Sdk"">
189+
<PropertyGroup>
190+
<WarningsAsErrors>NU1102;NU1603</WarningsAsErrors>
191+
</PropertyGroup>
192+
</Project>
193+
";
194+
var sut = new CsProjGenerator("netcoreapp3.1", null, null, null, true);
195+
196+
var xmlDoc = new XmlDocument();
197+
xmlDoc.LoadXml(withWarningsAsErrors);
198+
var (customProperties, sdkName) = sut.GetSettingsThatNeedToBeCopied(xmlDoc, TestAssemblyFileInfo);
199+
200+
AssertCustomProperties(@"<PropertyGroup>
201+
<WarningsAsErrors>NU1102;NU1603</WarningsAsErrors>
202+
</PropertyGroup>", customProperties);
203+
Assert.Equal("Microsoft.NET.Sdk", sdkName);
204+
}
205+
184206
[Fact]
185207
public void TheDefaultFilePathShouldBeUsedWhenAnAssemblyLocationIsEmpty()
186208
{

0 commit comments

Comments
 (0)