var options = new WebApplicationOptions
{
Args = args,
//这是因为从Windows中调用GetCurrentDirectory会返回:C:\WINDOWS\system32
//需要注意使用了WindowsService部署,就不能使用Console类,否则会报错
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
};
var builder = WebApplication.CreateBuilder(options);
if (WindowsServiceHelpers.IsWindowsService())
{
builder.Host.UseWindowsService();
}
// Add services to the container.
builder.Services.AddControllers(options =>
{
options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true; //兼容可为空类型的模型校验问题
}).AddNewtonsoftJson(options =>
{
options.UseMemberCasing();
});
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
标签:Core,Windows,builder,WindowsServiceHelpers,6.0,NET,options
From: https://www.cnblogs.com/krockey/p/17990413