You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
xUnit tests may not be discovered now that the .NET SDK trims packages from deps.json when they don't have any assets #49248
The issue is that xUnit looks for libraries nanmed "xunit" or "xunit.core" in the deps.json when trying to figure out whether an assembly is an xUnit test assembly. The xunit.core package doesn't include any runtime assets, only MSBuild .props and .targets files that are imported. This means that it may be removed from the deps.json file.
The xunit.core package depends on xunit.extensibility.core and xunit.extensibility.execution, both of which do have runtime assets. So if there are not references to those packages via another path, then the SDK will keep xunit.core in the deps.json. However, if there are other libraries that depend on xunit.extensibility.core and xunit.extensibility.execution, then the SDK will drop xunit.core from the deps.json and xUnit won't discover any tests.
Add the ability to opt in or out of the new behavior
Hardcode "xunit.core" in DependencyContextBuilder to prevent it from being dropped
Change the graph algorithm in DependencyContextBuilder so that we don't drop libraries with transitive dependencies on runtime assets, even if those runtime assets are referred to via a different path.
Another option for fixing would be to make changes to the xunit detection to be more flexible - I don't know that we have any support around the schema or structure of this file so I'm not sure we should encourage the use of it in external libraries.
Another option for fixing would be to make changes to the xunit detection to be more flexible - I don't know that we have any support around the schema or structure of this file so I'm not sure we should encourage the use of it in external libraries.
There is a risk with that if the user didn't notice their tests are not running and they didn't update the xunit dependency though. The failure here can be silent in many cases, as seen in aspnetcore repo.
(And yes, the 3.x builds of xunit.runner.visualstudio are still able to run both v1 and v2 test projects, in addition to adding support for v3 test projects.)
Updating aspnetcore to xunit.runner.visualstudio 3.x in dotnet/aspnetcore#62250. This issue is still relevant though for users of xunit.runner.visualstudio 2.x
This issue is still relevant though for users of xunit.runner.visualstudio 2.x
Is there any reason anybody should be stuck on this old version? If there are compatibility issues, we'd like to know about them. We currently have no plans to release any more 2.x builds of xunit.runner.visualstudio, so we would generally call this issue "won't fix", since there exists a fairly simple workaround (use a current build).
(I'm aware of the one potentially significant issues: net472 minimum. Unfortunately, the fact that netstandard2.0 can be broken on .NET Framework < 4.7.2 mandates this change for us.)
Given that it seems like a workaround for the issue is to update to v3 of xunit.runner.visualstudio, I'm now leaning towards adressing this by adding a property to opt out of the new behavior where libraries without runtime assets are trimmed from the deps.json.
That means this issue could still be hit but it sounds like it may not have a huge impact, and if it did affect you, you could work around it by updating the xunit package or by setting a property to revert to the old behavior.
and if it did affect you, you could work around it by updating the xunit package or by setting a property to revert to the old behavior.
My problem here is "how" it is affecting me. It could be silently causing my tests to not run, and I could notice very late. A week of silent failures have already introduced few failing tests in aspnetcore repo. I wouldn't mind the breaking change here if it was obvious (i.e, the user is getting some error message and he will look for how to fix it)
list the breaking change on .NET 10 announcements and ask @bradwilson if he can update his documentation to mention this issue. (that would be my pick)
undo the breaking change
I am failing to see how the opt-out mechanism will help because I won't notice my tests are not run and when I notice, I can update to the new xunit runner that is not affected by the error.
Also note that this is affecting xunit but this could affect other libraries that are relying on the same behavior hence being explicit and calling out the "break" in .NET 10 SDK notes seems the best to me.
I could, in theory, replace the .deps.json code with Cecil code (like from v3) but it wouldn't help people realize they need to upgrade (and it would only be for people stuck on .NET Framework < 4.7.2, which I suppose if you're sticking with a 9 year old framework and don't move on, you're probably not upgrading all your dependencies on a regular basis 😂).
Opt-out might be a nice thing to have in the back pocket in case we have anyone else who hits this. I do think updating the runner is a reasonable thing to do since the new runner is backward compatible with old tests.
Just do double-check here - the problem isn't that xunit needs the app to list assemblies that it doesn't deploy, right? It's only these empty packages that it probes for?
Is there anything we can see in what Xunit is doing here and try to extrapolate that to a pattern we can search for to understand if others might do it?
It's only these empty packages that it probes for?
Right, it looks for those package references rather than the assemblies, because at least with v2, adding package xunit.core means a unit test vs. adding package xunit.extensibility.core which means an extension project.
FWIW, checking for assembly references is what we do in xunit.v3.runner.utility with Cecil, since we couldn't check for NuGet packages, so moving to that in a new 2.x release of xunit.runner.visualstudio would be parallel functionally, and the only reason to do that would be so people could continue to test projects linked with .NET Framework 4.6.2, 4.7, and 4.7.1.
Thanks for the feedback so far folks. Here's what I'm currently planning to do:
Special case "xunit.core" so that it's never trimmed from the deps.json file
Add an opt-out property to disable the new deps.json trimming logic entirely.
With these changes we won't break xUnit v2, and if there are other tools out there that rely on deps.json in a similar way there will be a workaround of setting a property to avoid the trimming.
We'll also add a breaking change notice to .NET 10 so that the change is documented.
Activity
dsplaisted commentedon Jun 4, 2025
Some options for fixing:
dsplaisted commentedon Jun 4, 2025
@ericstj @jasonmalinowski @ViktorHofer @agocke FYI, The most recent deps.json changes (#46218) have the potential to prevent xUnit from discovering any tests. See above.
Feedback is welcome on how we should address this, I lean towards the last option.
baronfel commentedon Jun 4, 2025
Another option for fixing would be to make changes to the xunit detection to be more flexible - I don't know that we have any support around the schema or structure of this file so I'm not sure we should encourage the use of it in external libraries.
ViktorHofer commentedon Jun 4, 2025
Yes, the last option sounds best to me.
Youssef1313 commentedon Jun 4, 2025
FYI @bradwilson.
Youssef1313 commentedon Jun 4, 2025
There is a risk with that if the user didn't notice their tests are not running and they didn't update the xunit dependency though. The failure here can be silent in many cases, as seen in aspnetcore repo.
baronfel commentedon Jun 4, 2025
@Youssef1313 I tend to agree with you, just mentioning that option for completeness 👍
bradwilson commentedon Jun 4, 2025
The code you linked is no longer current. Have you tried using a 3.x build of
xunit.runner.visualstudio? Those usexunit.v3.runner.utility, which relies on Cecil to do the assembly probing rather than looking for the.deps.jsonfile: https://github.com/xunit/xunit/blob/0024bf168314d7f5db0ee07da0c517f7bd377ca9/src/xunit.v3.runner.common/Utility/AssemblyUtility.cs#L41-L47(And yes, the 3.x builds of
xunit.runner.visualstudioare still able to run both v1 and v2 test projects, in addition to adding support for v3 test projects.)Youssef1313 commentedon Jun 4, 2025
Updating aspnetcore to xunit.runner.visualstudio 3.x in dotnet/aspnetcore#62250. This issue is still relevant though for users of xunit.runner.visualstudio 2.x
bradwilson commentedon Jun 4, 2025
Is there any reason anybody should be stuck on this old version? If there are compatibility issues, we'd like to know about them. We currently have no plans to release any more 2.x builds of
xunit.runner.visualstudio, so we would generally call this issue "won't fix", since there exists a fairly simple workaround (use a current build).bradwilson commentedon Jun 4, 2025
(I'm aware of the one potentially significant issues:
net472minimum. Unfortunately, the fact thatnetstandard2.0can be broken on .NET Framework < 4.7.2 mandates this change for us.)dsplaisted commentedon Jun 5, 2025
Given that it seems like a workaround for the issue is to update to v3 of xunit.runner.visualstudio, I'm now leaning towards adressing this by adding a property to opt out of the new behavior where libraries without runtime assets are trimmed from the deps.json.
That means this issue could still be hit but it sounds like it may not have a huge impact, and if it did affect you, you could work around it by updating the xunit package or by setting a property to revert to the old behavior.
Feedback welcome.
Youssef1313 commentedon Jun 5, 2025
My problem here is "how" it is affecting me. It could be silently causing my tests to not run, and I could notice very late. A week of silent failures have already introduced few failing tests in aspnetcore repo. I wouldn't mind the breaking change here if it was obvious (i.e, the user is getting some error message and he will look for how to fix it)
Evangelink commentedon Jun 5, 2025
IMO we should either:
I am failing to see how the opt-out mechanism will help because I won't notice my tests are not run and when I notice, I can update to the new xunit runner that is not affected by the error.
Also note that this is affecting xunit but this could affect other libraries that are relying on the same behavior hence being explicit and calling out the "break" in .NET 10 SDK notes seems the best to me.
bradwilson commentedon Jun 5, 2025
I could, in theory, replace the .deps.json code with Cecil code (like from v3) but it wouldn't help people realize they need to upgrade (and it would only be for people stuck on .NET Framework < 4.7.2, which I suppose if you're sticking with a 9 year old framework and don't move on, you're probably not upgrading all your dependencies on a regular basis 😂).
bradwilson commentedon Jun 5, 2025
I also don't think we're going to document our way out of a problem that isn't obvious to begin with.
ericstj commentedon Jun 5, 2025
Opt-out might be a nice thing to have in the back pocket in case we have anyone else who hits this. I do think updating the runner is a reasonable thing to do since the new runner is backward compatible with old tests.
Just do double-check here - the problem isn't that xunit needs the app to list assemblies that it doesn't deploy, right? It's only these empty packages that it probes for?
Is there anything we can see in what Xunit is doing here and try to extrapolate that to a pattern we can search for to understand if others might do it?
bradwilson commentedon Jun 5, 2025
Right, it looks for those package references rather than the assemblies, because at least with v2, adding package
xunit.coremeans a unit test vs. adding packagexunit.extensibility.corewhich means an extension project.FWIW, checking for assembly references is what we do in
xunit.v3.runner.utilitywith Cecil, since we couldn't check for NuGet packages, so moving to that in a new 2.x release ofxunit.runner.visualstudiowould be parallel functionally, and the only reason to do that would be so people could continue to test projects linked with .NET Framework 4.6.2, 4.7, and 4.7.1.dsplaisted commentedon Jun 6, 2025
Thanks for the feedback so far folks. Here's what I'm currently planning to do:
With these changes we won't break xUnit v2, and if there are other tools out there that rely on deps.json in a similar way there will be a workaround of setting a property to avoid the trimming.
We'll also add a breaking change notice to .NET 10 so that the change is documented.
Don't trim xunit.core from deps.json
Update to xunit.runner.visualstudio 3.1.1
Update to xunit.runner.visualstudio 3.1.1
Update to xunit.runner.visualstudio 3.1.1
Update to xunit.runner.visualstudio 3.1.1
Update to xunit.runner.visualstudio 3.1.1 (#79343)
Merge main (#79424)