C
C#3mo ago
Odd_Dev_404

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
Denis
Denis3mo ago
Is the code in your console project only within the top level statement? Is your code in marked as anything else than public?
Odd_Dev_404
Odd_Dev_4043mo ago
@Denis - Thanks for the reply. This is my code.
Odd_Dev_404
Odd_Dev_4043mo ago
No description
No description
Odd_Dev_404
Odd_Dev_4043mo ago
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.
Odd_Dev_404
Odd_Dev_4043mo ago
No description
SinFluxx
SinFluxx3mo ago
What's the error / what does your Operations class look like?
Odd_Dev_404
Odd_Dev_4043mo ago
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 👍
SinFluxx
SinFluxx3mo ago
Cool, $close
MODiX
MODiX3mo ago
Use the /close command to mark a forum thread as answered