Having to manually add a project reference to csproj file when creating Unit Tests

Viewed 18

I'm following this tutorial on how to create Unit Tests for my C# project. However when I'm attempting to import one project into another I get an error saying the type or namespace cannot be found. I was able to fix it by manually adding this to the csproj file of the unit tests project:

<ItemGroup>
<ProjectReference Include="..\MyNEAT\MyNEAT.csproj" />
</ItemGroup>

Is there a reason I'm having to do this (as the tutorial doesn't mention having to do this at all) and is there way I can create Unit Tests without having to do this every time?

1 Answers

You have to do it, but the IDE has a graphical way to do it. You needn't edit the file in a text editor.

Add reference context menu

And then select the Product:

Select the project

Do it in the correct direction:

  1. Your Unit Test must reference your Product
  2. Your Product must not reference the Unit Test
Related