Launch ASP.NET Core Web-API programmatically - c#

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.

Related

How to add .net core Web API project to an existing .NET core (3.1) Web Application project?

I want to add .NET Core Web API project to an existing .NET core (3.1) Web Application project, with JWT Token Authentication with Identity Framework with routing and all..
Please Do we have any suggestion & is this possible & good idea to combine both the Projects?
Its not good idea to add .NET Core Web API to an existing .NET core (3.1) Web Application project.. first of all you have to set "Default Project" from your solution, and both project have entry point or start up class.
So if you want you can marge both project, you can move your controller and service from .NET Core Web API to .NET core (3.1) Web Application project, that may large work if your project size is big...

What is the correct order of installation for running a DotNet Core web application on a local IIS server?

I run a local IIS Server with a DotNot Core 2.1 application deployed to it. I like to keep up to date with the latest security patches that are released monthly and I use the Core download page to do so.
My question is, what ALL do I need to install each time and in what order. I usually find a Framework installer and I chose the SDK just to make I have everything. Then I find a ASPNET.CORE installer and I run those in. Finally, I run the Web Hosting Bundle.
Am I doing too much? Do some of these items copy over the same assets? What is the correct proceedure?
If you need to host an asp.net core web app, follow the Host ASP.NET Core on Windows with IIS Guide.
In terms of installing things, follow the Install the .NET Core Hosting Bundle Section
The bundle will install 3 things:
.NET Core Runtime
.NET Core Library
ASP.NET Core Module (for IIS)

.NET Core 2.0 and Aurelia

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

Hosting ASP.NET Core application on shared Linux hosting

Now asp.net core has been released so we can develop/deploy .net application on any platform.
I am trying to play with asp.net core and able to run my application on ubantu os(On Virtual Machine). But i just wanted to hosted dot net core application on shared linux hosting environment where simply upload published file.
I was following Tony's blog, to play with core.
We need DNVM, DNU and DNX to run application, but we don't have terminal to execute these commands on shared hosting.
Help me figure out the solution.
It is somewhat possible... and actually, Scott Hanselman just did it using .NET Core 2.1 (still in preview, although). He got it running on GoDaddy's shared Linux plan. You may follow his step by step here, but you are strongly adviced not to do it.

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