Skip to content

[Bug]: Referencing TUnit.Core as a transitive dependency resets TUnitImplicitUsings #5277

@Lexy2

Description

@Lexy2

Description

This bug is related to #5208.

<TUnitImplicitUsings> is reset to true when referencing TUnit.Core as a transitive dependency.
Additionally, TUnit source generators are enabled in projects that don't reference TUnit as long as those projects reference another project that references TUnit :-)

Judging by the build log, the property from Directory.Build.props is unconditionally reassigned in TUnit.Core.props around here:

    <PropertyGroup Condition="'$(XunitPackageReferenceFound)' == 'false'">
        <TUnitImplicitUsings>true</TUnitImplicitUsings>
    </PropertyGroup>

My projects don't reference XUnit and this configuration item doesn't seem to be justified here.

Expected Behavior

Referencing TUnit in dependent project does not enable source generators and implicit usings in the current project.

Actual Behavior

error CS0104: 'Test' is an ambiguous reference between 'TUnit.Core.TestAttribute' and 'NUnit.Framework.TestAttribute'
CSC : warning CS8785: Generator 'TestMetadataGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'No test attribute found on <TestName>'.

Steps to Reproduce

tunit-transitive-bug.zip

Minimal repro attached.

TUnit Version

1.22.3

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

D:\src\tunit-transitive-bug\NUnitTest\UnitTest1.cs(7,6): error CS0104: 'Test' is an ambiguous reference between 'TUnit.Core.TestAttribute' and 'NUnit.Framework.TestAttribute'
Get projects properties with MSBuild didn't execute properly with exit code: 1.

Additional Context

<TUnitImplicitUsings>false</TUnitImplicitUsings> has to be set in every project referencing the one with TUnit.

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions