C#.NET Core Console Application with Xunit not detecting the console project as a project reference.
I have created a C#.NET Core Console Application. And added new Xunit project under the same solution. Then added a project reference to the console application project under Xunit project, and then I can write unit tests for the console application. I can see that the reference has been added successfully as below:
<ItemGroup>
<ProjectReference Include="..\ConsoleApp1\ConsoleApp1.csproj" />
</ItemGroup>
But when I was trying to use console application's classes after importing the namespace to the unit test project, it doesn't detect as expected.
Both projects have the same .NET core version 8.
Can someone help me with this please?
9 Replies
Is the code in your console project only within the top level statement?
Is your code in marked as anything else than public?
@Denis - Thanks for the reply.
This is my code.
I noticed that somehwere on Stackoverflow had mentioned that creating a public class in a console app does the trick.
I tried that, but even intellisense not working for the namespace of the console app, and cannot instantiate a new class object.
What's the error / what does your Operations class look like?
Error was intellisense not working inside the unit test when I was trying to use the console app's namespace, and when I was trying to create a new class object it wasn't detecting/intellisense inside the unit test class.
But I found the solution now.
By default when I was creating a console application, it creates the Program class with main method as an internal class Program. So, since unit test project is outside the console app's project assembly, it blocks accessing it.
I created a new class with a public class, instead of internal class, and now it works!!
I think I can close this thread now.
Thanks everyone who replied 👍
Cool, $close
Use the /close command to mark a forum thread as answered