Troubleshooting program does not contain a static 'Main' method when it clearly does...?
Are the properties on the file set to Compile?
Program does not contain a static ‘Main’ method suitable for an entry point
Create a .NET Class Library project if you only want a library project. If this is a project that already exists, you can set the Project Output type to a DLL ("Class Library") instead of an Executable ("Windows Application"/"Console Application") in the project properties.
Program does not contain a static 'Main' method suitable for an entry point In .Net MAUI Xunit
You need to make a few modifications to make xUnit work. I have a sample repository here: https://github.com/jfversluis/MauiUnitTestSample
All the modifications are in the csproj
files of both projects and marked with a comment that starts with xUnit
.
- Add
net6.0
as a target in your .NET MAUI project.
<!-- xUnit: Add net6.0; here -->
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
- Make the
OutputType
of the .NET MAUI project exclude thenet6.0
target
<!-- xUnit: The condition here only excludes this for the unit test project -->
<OutputType Condition="'$(TargetFramework)' != 'net6.0'">Exe</OutputType>
- In your xUnit project add
UseMaui
if you need to reference .NET MAUI APIs
<!-- xUnit: Add UseMaui if you need access to .NET MAUI APIs-->
<UseMaui>true</UseMaui>
You should now be able to add and run unit tests!
CS5001 Program does not contain a static 'Main' method suitable for an entry point XUnit
You need to create a separate project for your unit tests. And do not declare a class with Main
method inside this project, xUnit has already a Main
method that it uses to run the tests.
And make sure that the "Discover tests in real time from C# ...." is checked under Tools > Options > Test > General
Otherwise, you will need to click on "Run All" to discover all your tests, each time you add a new one.
Related Topics
Disable Transitive Project Reference in .Net Standard 2
Reversible Shuffle Algorithm Using a Key
Apiresource VS APIscope VS Identityresource
How to Drag and Drop a Button from One Panel to Another Panel
Iapplicationactivationmanager::Activateapplication in C#
How to Split an Ienumerable<String> into Groups of Ienumerable<String>
C# Getting Value of Params Using Reflection
Openssl Encryption Using .Net Classes
Create Out-Of-Process Com in C#/.Net
How to Get Current User Who's Accessing an ASP.NET Application
An Expression Tree Lambda May Not Contain a Null Propagating Operator
How to Output Unicode String to Rtf (Using C#)
How to Change Originating Ip in Httpwebrequest