C
C#17mo ago
LukeJ

✅ Can no longer run console app after adding unit tests

I made a little test project that I've slowly been building onto. It's gotten big enough now that I've added NUnit unit tests to make it easier, but I seem to have done it wrong and now the app won't open. When I hit run it brings up a configuration window with the error on the bottom Error: Project has no runnable target frameworks defined. The Target framework parameter shows net6.0 though, so I'm not sure what the problem is. Here's what the csproj file looks like
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LanguageExt.Core" Version="4.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0-preview-20221221-03" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Console" Version="3.16.2" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LanguageExt.Core" Version="4.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0-preview-20221221-03" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Console" Version="3.16.2" />
</ItemGroup>

</Project>
I added in the Microsoft.NET.Test.Sdk to get the unit tests to appear in the test runner, but it also causes this error running it normally. Comparing it to a freshly made unit test project, the csproj looks about the same. I've definitely done something wrong in adding the nunit packages, but I have no idea what.
6 Replies
ero
ero17mo ago
Your tests should be in a separate project
LukeJ
LukeJ17mo ago
Ah. Wasn't aware of that, coming from Unity. That's... slightly annoying, but oh well. Thanks.
ero
ero17mo ago
it's not, tests have absolutely no business being in your release code
LukeJ
LukeJ17mo ago
It's annoying in that I now need two projects open that I need to swap between.
ero
ero17mo ago
That's the normal flow of most development Are you not using a proper IDE? You can have multiple projects in the same solution Rider and VS will display both just fine
LukeJ
LukeJ17mo ago
Even run the console app of one and the unit tests of the other? Huh. Ok then.