.NET Core 2.0 and Aurelia - c#

Here's my story: I created a solution in VS2017 which contains 3 projects: .NET Core 2.0 dll to store my models, WebAPI (which uses EF Core 2.0 code first) and blank Web Application. In the blank project I would like to create a frontend Aurelia app. So, I did 'au new --here' on that project, selected TypeScript as my transpiler. Now, I have a solution with 3 projects which doesn't build because of:
Error TS5055 Build:Cannot write file 'XX/karma.conf.js' because it would overwrite input file.
I updated TypeScript to 2.3 by adding a proper entry to .csproj but still cannot compile my solution in VS2017.
My question is: how to add an Aurelia project to .NET Core 2.0 solution and get "au run --watch" works for it? I followed this post: http://mobilemancer.com/2016/10/19/aurelia-spa-typescript-dotnet-core/ but it seems not to consider all possible scenarios.
Please help me get started with .NET Core 2.0 Aurelia + WebAPI as I've been struggling with that for a couple of days.

You can look at the code from Aurelia-Typescript-Skeleton from GitHub https://github.com/aurelia/skeleton-navigation/tree/master/skeleton-typescript-aspnetcore
They have created asp.net core application and basic structure for aurelia and typescript.
You can install SPA Templates from ASP.NET core 2.0 with CLI command dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
There you can find reach set of templates to start with ASP.NET core 2.0

Related

Referencing .Net Core project from .NET MAUI

I have 2 projects in my solution - .Net Maui(GUI) and ASP.Net Core Web API(API)
After adding a project reference to my GUI I get the following errors:
And I can find very little information on that, although I'm probably looking in wrong places. Can you give a hand with that?
Edit:
To complete/expand my question, I'm looking for a way to structer my solution a little bit better, I don't want to have everything in .NET Maui project.
I was following this tutorial https://www.youtube.com/watch?v=LrZwd-f0M4I
The author does create .NET Core project for API and Db connection
(EF Core) and then he uses the Api in .NET Maui
What am I missing?

Updating Razor Pages project to ASP.Net Core 5.0: why should I depend on MySQL server version?

My Razor Pages project is experimental one. It is targeted on working with MySQL database for Visual Studio. Initially, I built the project on ASP .NET Core 2.2 and successfully upgraded to ASP.Net Core 3.1. Now I’m trying to migrate the project to ASP .NET Core 5.0.
After updating the project as recommended in Migrate from ASP.NET Core 3.1 to 5.0, I have encountered the following error in “Startup.cs” file:Fig.1
The next image depicts the error code:Fig 2
Installed packages list:Fig 3
I tried to do some things to fix the error:Fig.4
In the figure 4, you can see that I’m going to add a parameter. I added the one, which I set to “null”. The error eliminated but the problem remained. After successful project compilation, I started the project, but received the following error:Fig. 5
In the figure 5, you can see that the source of the error is “Pamelo.EntityFrameworkCore.MySql” and the message is “The Server Version has not been set”. However, why it has not been auto detected? Well, if the second parameter is not to be set to “null”, then how this parameter is to be set?
To answer this question really helped me the following article:Pomelo.EntityFrameworkCore.MySql
Now the “error” line works well and looks as follows
services.AddDbContext<ApplicationContext>(options => options.UseMySql(
connection,
new MySqlServerVersion(new Version(5, 7, 17))
));
The project works well, but questions remain. What can I do if I can’t find server version? Why auto detect does not work as in the earlier package version for ASP .NET Core 3.1? Why should I depend on the server version?
Returning to the figures 1 – 3, I have the question:
Should I expect that the original code (auto detect) would work after Pamelo.EntityFrameworkCore.MySql (v 5.0.0) package release version will be published?
Any help would be appreciated.

Can't find global application class nor Global. asax file

I want to add an API service to my existing .NET web application.
I was following this tutorial, but couldn't found any option to add web service.
Then I followed these two questions on Stackoverflow (Where is the Global.asax.cs file? and Global.asax file is missing on my Asp.Net Empty Web application project) but couldn't find the Add option for the global application class. How can I resolve this issue? Am I doing something wrong?
I tried to create a new solution, the problem is the same.
I'm using VisualStudio 2019 16.4.6
My project's targeted framework is .NET Core 3.1
If there is any tutorial or written document for adding web API to an existing project please give me, that would be very helpful. I tried to follow this blog and installed Microsoft.AspNet.WebApi.Core and got this warning -
Package 'Microsoft.AspNet.WebApi.Core 5.2.7' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
With ASP.NET Core, the entry point to an application is Startup, and you no longer have a dependency on Global.asax.
You can find more about it on this link
To consume an API you can use RestSharp in your Asp.net Core Application.
You can check this link to learn more about consuming an API using RestSharp in your Asp.net Core Application.
My project's targeted framework is .NET Core 3.1
Global.asax.cs will not be generated if you use ASP.NET Core. You have to use older version of ASP.NET, for example ASP.NET 4 (4.7.2) if you want to follow that old tutorial.
Or you can try a tutorial for WebApi using Asp.Net Core like this one: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio

Launch ASP.NET Core Web-API programmatically

How do I launch an ASP.NET Core Web-API programmatically from C#? The API should launch after I click on a button in a form.
I already added my API to my solution via Add -> Existing Project... but I don't know how to launch it from a different Project.
The Web-API is running on .NET Core 2.0 and I want to launch it from a project using .NET Framework 4
Probably you are looking for something like this(link)
dotnet run [-c|--configuration] [-f|--framework] [--force] [--launch-profile] [--no-build] [--no-dependencies]
[--no-launch-profile] [--no-restore] [-p|--project] [--runtime] [[--] [application arguments]]
dotnet run [-h|--help]
You can also try to run the application as a Windows Service, and start the service on click.
Here is a sample project showcasing hosting of ASP.NET Core app in WPF: https://github.com/mkArtakMSFT/Samples/tree/master/WpfAspNetCore
Couple of things to pay attention to:
The .NET Framework 4.6.1 is the minimum version which can host ASP.NET Core apps
This sample is dummy and doesn't have much configuration (based off of empty ASP.NET Core Web app template content). You can, however, add reference to the Microsoft.AspNetCore.Mvc package to add support for MVC.

What is the difference between creating a project ASP.NET Core (.NET Core) and ASP.NET Core (.NET Framework)

I don't see clearly the main difference between the last two project types, actually which sense have the last one? .NET Core and .NET Framework?
The difference is whether you will be targeting the .Net Core Framework or the Full .Net Framework. And this difference shows up for example in the project.json file.
Another thing to know about is that when you use the "ASP.NET Core Web Application (.NET Framework)" template it's much easier to link to .Net Library Projects that target the full framework when using Visual Studio. It's possible to do it using the "ASP.NET Core Web Application (.NET Core)" template but it requires some manual editing of the project.json file.
It may also be worth mentioning that if you target the Full Framework the web application must be deployed on Windows, whereas targeting the .Net Core framework allows the web application to be deployed to non-Windows environments. But the .Net Core Framework is not as feature rich as the Full Framework. (It has no drawing routines for resizing images for instance). You can read more about choosing the right framework here: https://docs.asp.net/en/1.0.0-rc1/getting-started/choosing-the-right-dotnet.html
Either way, no matter which of these two templates you select, you will be creating a project for creating an ASP.NET Core application.
Some differences in the actual projects created
Here is what the solution looks like in Visual Studio 2015 Update 3 when "ASP.NET Core Web Application (.NET Core)" is chosen (with Empty option):
And here is its project.json file:
Here is what the solution looks like in Visual Studio 2015 Update 3 when "ASP.NET Core Web Application (.NET Framework)" is chosen (with Empty option):
And here is its project.json file:
ASP.NET Core can run on top of .NET Core or the full .NET Framework. So there's a template depending on whether you want to build on .NET Core or the full .NET Framework.
Here's an infographic that Microsoft put together that visually demonstrates the concept:
No matter which template you choose, you can always edit your configuration to target both at the same time. But the templates just help you get started with one or the other.

Categories