十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
No support for filters: For example, no support for IAsyncAuthorizationFilter, IAsyncActionFilter, IAsyncExceptionFilter, IAsyncResultFilter, and IAsyncResourceFilter.
为平武等地区用户提供了全套网页设计制作服务,及平武网站建设行业解决方案。主营业务为成都网站建设、网站设计、平武网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
No support for model binding, i.e. IModelBinderProvider, IModelBinder. Support can be added with a custom binding shim.
No support for binding from forms. This includes binding IFormFile. We plan to add support for IFormFile in the future.
No built-in support for validation, i.e. IModelValidator
No support for application parts or the application model. There's no way to apply or build your own conventions.
No built-in view rendering support. We recommend using Razor Pages for rendering views.
No support for JsonPatch
No support for OData
No support for ApiVersioning. See this issue for more details.
Install-Package Microsoft.Extensions.Hosting.WindowsServices
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseWindowsService(); //add this line
var app = builder.Build();
发布从不同维度划分分为2种
a. 是否为单文件
b. 是否Self-Contained
所以组合下来就是:
a. 基于Framework的多文件
b. 基于Framework的单文件
c. 带运行时的多文件
d. 带运行时的单文件
https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md#user-experience
命令如下:
dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true
PowerShell
//https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-7.2
New-Service -Name {服务名} -BinaryPathName "{exe文件路径}" -Description "{描述}" -DisplayName "{显示名}" -StartupType Automatic
或者使用sc.exe
sc create [service name] [binPath= ] ...
OPTIONS:
NOTE: The option name includes the equal sign.
A space is required between the equal sign and the value.
type=
(default = own)
start=
(default = demand)
error=
(default = normal)
binPath=
group=
tag=
depend=
obj=
(default = LocalSystem)
DisplayName=
password=
PowerShell
Start-Service ServiceName
不出意外的话会报错
Start-Service : Service 'Service1 (Service1)' cannot be started due to the following error: Cannot start service Service1 on computer '.'.
解决该问题有2个方案,后面官方修复了就不用这么麻烦了
a. 改代码
using Microsoft.Extensions.Hosting.WindowsServices;
var options = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
};
var builder = WebApplication.CreateBuilder(options);
builder.Host.UseWindowsService();
b. 上面代码可以看出来,其实就是Windows Service需要的ContentRootPath
有问题
那么我们可以在启动服务的时候指定--contentRoot
参数
sc config MyWebAppServiceTest binPath= "$pwdWebApplication.exe --contentRoot $pwd"
本段参考:
https://stackoverflow.com/questions/69124310/asp-net-core-net-6-preview-7-windows-service
https://github.com/dotnet/AspNetCore.Docs/issues/23387