Skip to content

Commit 801788c

Browse files
committed
Don't trim xunit.core from deps.json
Fixes #49248
1 parent 47d0bba commit 801788c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,14 @@ public DependencyContext Build(string[] userRuntimeAssemblies = null)
362362
var lib = unprocessedLibraries.First();
363363
unprocessedLibraries.Remove(lib);
364364

365+
if (lib.Library.Name.Equals("xunit.core", StringComparison.OrdinalIgnoreCase))
366+
{
367+
// Special case xunit.core, it should not be removed because the xUnit v2 runner looks for this library in the deps.json to
368+
// identify test projects.
369+
// See https://github.com/dotnet/sdk/issues/49248
370+
continue;
371+
}
372+
365373
if (lib.Library.RuntimeAssemblyGroups.Count == 0 && lib.Library.NativeLibraryGroups.Count == 0 && lib.Library.ResourceAssemblies.Count == 0)
366374
{
367375
if (lib.Library.Dependencies.All(d => !libraries.TryGetValue(d.Name, out var dependency) || dependency.Dependents.Count > 1))

test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopLibrary.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,35 @@ public void PackageWithoutAssets_ShouldNotShowUpInDepsJson()
150150
var buildCommand = new BuildCommand(testAsset);
151151
buildCommand.Execute().Should().Pass();
152152

153-
using (var depsJsonFileStream = File.OpenRead(Path.Combine(buildCommand.GetOutputDirectory(ToolsetInfo.CurrentTargetFramework).FullName, "PackageWithoutAssets_ShouldNotShowUpInDepsJson.deps.json")))
153+
using (var depsJsonFileStream = File.OpenRead(Path.Combine(buildCommand.GetOutputDirectory(ToolsetInfo.CurrentTargetFramework).FullName, $"{testProject.Name}.deps.json")))
154154
{
155155
var dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream);
156156
dependencyContext.RuntimeLibraries.Any(l => l.Name.Equals("Nerdbank.GitVersioning")).Should().BeFalse();
157157
}
158158
}
159159

160+
[Fact]
161+
public void XUnitCoreIsNotTrimmed()
162+
{
163+
// Regression test for https://github.com/dotnet/sdk/issues/49248
164+
165+
var testProject = new TestProject();
166+
testProject.PackageReferences.Add(new TestPackageReference("xunit.core", "2.9.3"));
167+
testProject.PackageReferences.Add(new TestPackageReference("xunit.extensibility.core", "2.9.3"));
168+
testProject.PackageReferences.Add(new TestPackageReference("xunit.extensibility.execution", "2.9.3"));
169+
170+
var testAsset = _testAssetsManager.CreateTestProject(testProject);
171+
172+
var buildCommand = new BuildCommand(testAsset);
173+
buildCommand.Execute().Should().Pass();
174+
175+
using (var depsJsonFileStream = File.OpenRead(Path.Combine(buildCommand.GetOutputDirectory(ToolsetInfo.CurrentTargetFramework).FullName, $"{testProject.Name}.deps.json")))
176+
{
177+
var dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream);
178+
dependencyContext.RuntimeLibraries.Any(l => l.Name.Equals("xunit.core")).Should().BeTrue();
179+
}
180+
}
181+
160182
[Fact]
161183
public void ProjectNameCanMatchPackageReferenceName()
162184
{

0 commit comments

Comments
 (0)