Launch ASP.NET Core Web-API programmatically

亡梦爱人 提交于 2019-12-13 16:07:37

问题


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


回答1:


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]




回答2:


You can also try to run the application as a Windows Service, and start the service on click.




回答3:


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.


来源:https://stackoverflow.com/questions/50796931/launch-asp-net-core-web-api-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!