Asp.net core 从编译的dll运行dotnet core api
我正在尝试在MacOs上运行dotnet core WebApi。使用Asp.net core 从编译的dll运行dotnet core api,asp.net-core,.net-core,asp.net-core-webapi,Asp.net Core,.net Core,Asp.net Core Webapi,我正在尝试在MacOs上运行dotnet core WebApi。使用dotnet run运行项目效果很好,因为它是从源代码运行的 现在我想打包Api并在其他机器上运行它,因此我使用以下命令 dotnet publish WebApiX.sln-f netcoreapp2.0-c Release-o../output-r osx.10.12-x64 它打包了整个应用程序及其依赖项。在此之后,我想用dotnet WebApiX.Api.dll启动web服务器,但出现以下错误: 未处理的异常:Sys
dotnet run
运行项目效果很好,因为它是从源代码运行的
现在我想打包Api并在其他机器上运行它,因此我使用以下命令
dotnet publish WebApiX.sln-f netcoreapp2.0-c Release-o../output-r osx.10.12-x64
它打包了整个应用程序及其依赖项。在此之后,我想用dotnet WebApiX.Api.dll
启动web服务器,但出现以下错误:
未处理的异常:System.ArgumentNullException:值不能为空
无效的参数名称:pathFormat at
Microsoft.Extensions.Logging.FileLoggerExtensions.AddFile(iLogger工厂
loggerFactory、字符串路径格式、LogLevel minimumLevel、,
IDictionary`2
levelOverrides,布尔isJson,null`1
fileSizeLimitBytes,Nullable`1
retainedFileCountLimit)
此异常在启动类上显示的Configure方法中生成
public void配置(IApplicationBuilder应用程序、IHostingEnvironment环境、iLogger工厂)
{
//配置中间件
loggerFactory.AddFile(Configuration.GetSection(“LogsLocation”).Value);
app.UseMiddleware();
app.UseMiddleware();
app.UseAuthentication();
app.UseMvc();
}
出于测试目的,我尝试移除测线记录器工厂。。
这很奇怪,因为现在的错误不同了
Unhandled Exception: System.InvalidOperationException: Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddMvc' inside the call to 'ConfigureServices(...)' in the application startup code.
at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)
at WeidertAuth.Api.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in /Users/mariomarques/Documents/Avnoconn/Projects/WEIDERT/WeidertServices/weidert.auth/WeidertAuth.Api/Startup.cs:line 249
您应该向项目文件(.csproj)添加运行时标识符,如下所示:
<RuntimeIdentifiers>osx.10.12-x64</RuntimeIdentifiers>
然后,您可以通过以下路径在project中找到项目的可执行文件:
MyProject/bin/dist/osx
希望您会觉得这很有用。尝试使用调试配置发布,看看错误是否仍然存在。如果您共享使用
的部分代码,这可能会有所帮助。AddFile
方法使用调试配置运行会产生同样的结果。我想这与配置有关。问题被编辑为包括启动类上显示的配置方法(即引发异常的方法)。您能否在appSettings
文件中共享相关部分<代码>配置。GetSection将查找一个名为“LogsLocation”的节,如果该节没有值,则可能是问题所在,我已确保它有值。事实上,我删除了这一行,现在错误不同了
dotnet restore
// publish for macos
dotnet publish -r osx.10.12-x64 --output bin/dist/osx