Program does not contain a static 'Main' method suitable for an entry point In .Net MAUI Xunit - xunit

I am getting "Program does not contain a static 'Main' method suitable for an entry point" error while run the Xunit project in .NET MAUI
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
Reproduce :
Create an MAUI application and add a new project XUnit to the solution.
Reference the MAUI project to the XUnit project.
Run the Test cases then get the above exception.
Using Visual Studio 17.3 Preview 2.0

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 the net6.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!

Related

Can't Add Reference to MVC 6 Project (.Net Core w/ .Net Framework) from Another Project

I'm running Visual Studio 2015 Update 3. I chose to create a .Net Core Project with .Net framework option specifically to use MVC 6. I have some classes in the project that I would like to reference from a console application project that I have included in the same solution. Although I can successfully add a reference to the .Net Core Project from the Console App, when I try to use the class from the console app, i'm unable to successfully add a using statement. It was my understanding that using the project template .Net Core App "With Net Framework" would prevent such issues. I've seen other posts regarding csproj xproj incompatibility. But i'm trying to add the reference from one xproj to another xproj. Is this even supported anymore? What a mess.
FYI: I also disabled resharper.
add the reference from one xproj to another xproj
If I understand correctly, the projects you are trying to link are both using project.json, right? This can be done by editing the project.json files. For example, you have "WebApp" and want to reference "ClassLib", edit the project.json file in the "WebApp" project to contain:
{
"dependencies": {
"ClassLib": {
"type": "project"
}
}
}
This part assumes that "ClassLib" is targeting a framework that is compatible with "WebApp", as listed in the "frameworks" section in project.json If your WebApp is targeting .NET Framework 4.6 (net46), then Class Lib should also target net46 or one of the frameworks compatible with "net46", such as "net451" or "netstandard1.3".

Can I use .net core on visual studio 2013

Is, or will .net core be available to use on visual studio 2013? Or it will be available only on visual studio 2015?
Thanks
Yes, it's possible to build against the .NET Core 5 contracts in Visual Studio 2013 by creating a Portable Class Library that targets .NET Framework 4.5 and Windows 8. You'll need to manually edit the .csproj file and add the following.
<PropertyGroup>
<ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework>
</PropertyGroup>
Then install the System.Runtime NuGet package and other .NET Core 5 packages.
The resulting assembly will be able to execute on any .NET Core 5-based framework including .NET Framework 4.6, ASP.NET 5 & .NET Native.
Note, this is the same technique used to build the .NET Core assemblies in the corefx repository.
An empty ASP.NET Core application can be built in VS2013 by doing the following steps:
Create a Console App project that targets at least .NET Framework 4.5.2 (using 4.5.1 is possible but support has now ended).
Install the following NuGet Packages:
Microsoft.AspNetCore.Hosting
Microsoft.AspNetCore.Server.Kestrel
Add existing item to project: [solution root]\packages\Libuv.[version]\runtimes\[os]\native\libuv.dll.
For the above file, set the property "Copy to Output Directory" to "Copy always"
Produce the necessary Startup.cs and Program.cs files
Basic Code (from the Getting Started Tutorial):
Program.cs
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Startup.cs
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Run(context =>
{
return context.Response.WriteAsync("Hello from ASP.NET Core!");
});
}
}

How to Build Entity Framework Project using Npanday

I am using Npnday 1.5. I have tried to build my project using Npanday. But DLL generated using Npanday has some issue. Because When I replace that DLL with other DLL which is generated by Visual Studio 2010, then my web application runs perfectly.
Have any one buid Entity Framework Project using Napanday??
Please tell me What are the steps required to build an entity framework project using Npanday.
Mainly what changes are required to do in POM.xml file???

Deployment items not working with new Visual Studio 2010 test project

I created a new Visual Studio 2010 Test Project.
<solution>
<test-project>
Resources
test-data.csv
tests.cs
I added one test with one deployment item attribute.
[TestMethod]
[DeploymentItem("test-project\Resources")]
public void Some_unit_test() { ... }
The file in the Resources folder is not moving to the test results out directory and is not being found by the test code.
You must check "Enable deployment" in the Deployment section of the Test Settings for that project.

How to get VS2010 to recognize my mstests generated by SpecFlow?

I have configured Specflow to target the MsTest framework (instead of NUnit) by specifying it like this in the app.config of my 'specs' class library:
<configSections>
<section name="specFlow"
type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<unitTestProvider name="MsTest.2010" />
</specFlow>
So once it's in place, I can see that my test fixtures are produced correctly by the Specflow custom tool, with correct TestClassAttribute() and methods, etc:
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.3.3.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
...
The specs class builds, but now I cannot run the tests using the Test --> Run --> All Tests in Solution inside Visual Studio 2010 on my vista 64 box. Why doesn't VS recognize these as valid tests to run?
As per Dror Helper and Alex Duggleby you'll want to add the following line to your .csproj file:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Add it after the FileAlignment element, and reload the project. It should now be an MS Test project and you get the MS Test functionality in the context of this project. The Guids mean:
{3AC096D0-A1C2-E12C-1390-A8335801FDAB} - Test Project
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - C# Class Library
I had to recreate the project as a Test Project and not merely a Class Library -- because I had started development with NUnit and SpecFlow, I had created a vanilla class library to hold my specs that had the NUnit attributes decorated. I thought I could simply change the app.config of this existing project to point at the mstest framework and stop using NUnit, but VS2010 never recognized the tests, despite the correct creation of the stubs by specflow's custom tool.
So...I added a new Test Project to my solution, moved all of my spec code to that new project, then recompiled, and viola, VS2010 recognizes the tests. I'm sure there is a GUID it is looking for in the XML of the .csproj file or something that tells it to wire up the testing framework, but I didn't dig that far.
Hope this helps someone.
To change your class library project template into a test project, modify the .csproj and add the following line:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
to the first property group element:
<PropertyGroup>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Resources