Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Microsoft.VisualStudio.SolutionPersistence.Model;
using Shouldly;
using System.Collections.Generic;
using System.IO;
using Xunit;

Expand Down Expand Up @@ -51,5 +52,47 @@ public void CanBuild()
.Project(project1)
.TryBuild(out _);
}

[Fact]
public void CanBuildWithGlobalProperties()
{
ProjectCreator project1 = ProjectCreator.Templates.SdkCsproj(path: Path.Combine(TestRootPath, "project1", "project1.csproj"));

Directory.CreateDirectory(Path.Combine(TestRootPath, "project1"));

File.WriteAllText(
Path.Combine(TestRootPath, "project1", "Xyz.cs"),
"""
public class Xyz
{
public void Boo(int value)
{
// This switch statement has no fallthrough, which triggers warning CS1522 normally.
switch (value)
{
}
}
}
""");

SolutionCreator solution = SolutionCreator.Create(Path.Combine(TestRootPath, "solution1.sln"))
.Configuration("Debug")
.Configuration("Release")
.Platform("Any CPU")
.Project(project1);

// When built normally, we should see a warning.
solution.TryBuild(restore: true, out _, out BuildOutput output);
output.Warnings.Count.ShouldBe(1);

// When built with a global property turning that warning off, we shouldn't see any.
IDictionary<string, string> globalProperties = new Dictionary<string, string>()
{
{ "NoWarn", "CS1522" },
};

solution.TryBuild(restore: true, globalProperties, out _, out output);
output.Warnings.ShouldBeEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private bool Build(bool restore, string[]? targets, IDictionary<string, string>?
Save();
}

bool result = BuildHost.TryBuild(FullPath, ProjectCollection, buildOutput, out targetOutputs, targets: targets);
bool result = BuildHost.TryBuild(FullPath, ProjectCollection, buildOutput, out targetOutputs, targets: targets, globalProperties: globalProperties);

return result;
}
Expand Down