Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error when one test project references another #3813

Closed
bdukes opened this issue Sep 11, 2024 · 11 comments · Fixed by #3891
Closed

Build error when one test project references another #3813

bdukes opened this issue Sep 11, 2024 · 11 comments · Fixed by #3891

Comments

@bdukes
Copy link

bdukes commented Sep 11, 2024

Describe the bug

Starting with MSTest 3.6.0, when one test project references another test project, warning CS0436 is emitted by the compiler because the same type is being compiled into two assemblies.

Steps To Reproduce

  1. Pull build-error-on-reference branch from bdukes/mstest-demo
  2. dotnet build

Expected behavior

The build command is successful.

Actual behavior

The build command fails with the following error:

I:\code\MSTestDemo\ProjectTwo.Tests\obj\Debug\net8.0\TestPlatformEntryPoint.cs(13,9): warning CS0436: The type 'SelfRegi
steredExtensions' in 'I:\code\MSTestDemo\ProjectTwo.Tests\obj\Debug\net8.0\AutoRegisteredExtensions.cs' conflicts with t
he imported type 'SelfRegisteredExtensions' in 'ProjectOne.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
. Using the type defined in 'I:\code\MSTestDemo\ProjectTwo.Tests\obj\Debug\net8.0\AutoRegisteredExtensions.cs'. [I:\code
\MSTestDemo\ProjectTwo.Tests\ProjectTwo.Tests.csproj]
@Evangelink
Copy link
Member

Hi @bdukes

Are you expecting to run tests from ProjectOne.Tests or is this a test helper project?

@bdukes
Copy link
Author

bdukes commented Sep 11, 2024

I'm expecting to run tests from both ProjectOne.Tests and ProjectTwo.Tests.

@Evangelink
Copy link
Member

I can reproduce the issue, I need a few more tests and investigation to suggest the proper fix.

@Evangelink Evangelink self-assigned this Sep 12, 2024
@jbcutting
Copy link

I'm also seeing this issue. In my case, we have various test helper projects referenced by our test projects. We do also have a few test projects referencing each other, but it's primarily an issue with test helpers.

@Evangelink
Copy link
Member

but it's primarily an issue with test helpers.

@jbcutting we do recommend to have test helper libraries as libraries and not executable.

@jbcutting
Copy link

jbcutting commented Sep 30, 2024

but it's primarily an issue with test helpers.

@jbcutting we do recommend to have test helper libraries as libraries and not executable.

They are libraries. We're not using executables for any of our test projects currently. We're still on MSTest 3.0.4 currently because I've run into something each time I've tried to update. I was hoping 3.6 would be my upgrade point, but I'm now waiting for 3.7 due to this.

Is there a way to avoid this with test helpers if I override a setting in 3.6? If I avoid exe test outputs altogether, would it bypass this issue?

@Evangelink
Copy link
Member

Fix will be ported to 3.6.1.

For your case, you don't even need the fix. In 3.6+ detecting if the project is library or application (through the OutputType).

If you are using MSTest.Sdk, by default we set <OutputType>Exe</OutputType> but for the test helpers, manually setting <OutputType>Library</OutputType> will solve the issue (you will see that among others MSTest.TestAdapter is not added).

If you are not using MSTest.Sdk, the default of .NET is <OutputType>Library</OutputType> and we ask to set it to <OutputType>Exe</OutputType> and add <EnableMSTestRunner>true</EnableMSTestRunner> on test applications but for helpers the default configuration is good.

I hope this helps.

@MarcoK80
Copy link

MarcoK80 commented Oct 2, 2024

This issue is not resolved if you have two projects and internalsvisible used to reuse an internal class.
Example:
UnitTest Project A has a FakeImplementation class that you want to reuse. InternalsVisibleTo is set for Project B
UnitTest Project B wants to use the Fakeimplementation class of Project A.

@bdukes
Copy link
Author

bdukes commented Oct 3, 2024

Upgrading to 3.6.1 resolved my issue, thanks @Evangelink!

@Evangelink
Copy link
Member

This issue is not resolved if you have two projects and internalsvisible used to reuse an internal class.

I'll run a few more tests. @MarcoK80 I'd like to discuss a little more about your scenario. I am still not fully sold on the idea of having an exe referencing an exe.

@3s-ap
Copy link

3s-ap commented Oct 15, 2024

This issue is not resolved if you have two projects and internalsvisible used to reuse an internal class.

I'll run a few more tests. @MarcoK80 I'd like to discuss a little more about your scenario. I am still not fully sold on the idea of having an exe referencing an exe.

@Evangelink I think it should not necessarily be two executables. I have two libraries where one has "internalsvisible" to the other and the issue is reproducible.

Update
I managed to fix it by adding this <GenerateTestingPlatformEntryPoint>false</GenerateTestingPlatformEntryPoint> to projects that do not have any tests. But it perhaps not fixes the root cause and will not work for multiple test assemblies referencing each other with "internalsvisible" (not tested)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants