发布后尝试 运行 应用程序时无法加载文件或程序集 Microsoft.EntityFrameworkCore.Design 版本 6.0.1
Could not load file or assembly Microsoft.EntityFrameworkCore.Design version 6.0.1 when trying to run app after publishing
我遇到了一个 ASP.NET Core 6 网络应用程序的问题,该应用程序有多个项目,其中一些项目根据要求具有视图和控制器,因此我将它们标记为 <Project Sdk="Microsoft.NET.Sdk.Razor">
并添加Startup中的应用部分如下:
由于我 运行 基于 SQL 服务器数据库构建实体 类 的脚手架命令行,同时创建迁移文件,我使用一种技术来拥有实体singularized/pluralized 在设计时创建它们。为此,我必须使用 Microsoft.EntityFrameworkCore.Design 提供的 DesignTime 服务,方法是创建 DesignTimeDbContextFactory、DesignTimeServices 和 Pluralizer 类 提供数据库连接和多元化服务,所以我将 Microsoft.EntityFrameworkCore.Design 包添加到主项目和后端(dbcontext 存储库)项目.
为了避免这个包被复制到输出发布文件夹(这个包不应该是生产的一部分),我在引用包的项目的 csproj 中添加了以下配置,根据找到的互联网文档:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<!--<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
</PackageReference>
当我尝试通过 运行ning dotnet SicotX.dll 命令行(是主项目)运行 发布的项目时,问题就出现了。该应用尝试 运行 但什么都不做
我检查了我添加到应用程序的日志,这是堆栈跟踪列表:
2022-03-02T21:31:07.8101308-05:00 [INF] () Creating the web host ...
2022-03-02T21:31:09.0961070-05:00 [FTL] (Microsoft.AspNetCore.Hosting.Diagnostics) Application startup exception
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.get_Types()
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.<>c__DisplayClass11_0.<Subscribe>b__0()
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
at Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSource..ctor(ControllerActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory, OrderedEndpointsSequenceProvider orderSequence)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, String name, String pattern, Object defaults, Object constraints, Object dataTokens)
at SicotX.Startup.<>c.<Configure>b__6_2(IEndpointRouteBuilder endpoint) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 266
at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action`1 configure)
at SicotX.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory log) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 264
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
File name: 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
2022-03-02T21:31:09.6087813-05:00 [FTL] () A fatal error ocurred creating the web host.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.get_Types()
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.<>c__DisplayClass11_0.<Subscribe>b__0()
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
at Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSource..ctor(ControllerActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory, OrderedEndpointsSequenceProvider orderSequence)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, String name, String pattern, Object defaults, Object constraints, Object dataTokens)
at SicotX.Startup.<>c.<Configure>b__6_2(IEndpointRouteBuilder endpoint) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 266
at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action`1 configure)
at SicotX.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory log) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 264
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at SicotX.Program.Main(String[] args) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Program.cs:line 47
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
File name: 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
我正在查看所有项目,看看是否有一些项目也引用了这个包,但只有主项目和后端项目被标记在 csproj 中,如上所述。
我正在尝试搜索问题是否由启动时加载的任何应用程序部分引起但没有成功。
重要提示:我的目标是避免 Microsoft.EntityFrameworkCore.Design 发布到生产环境,因为该包仅在设计时有效,并根据我一直在做的事情克服我面临的日志错误。
我在调试时没有遇到问题。
感谢任何帮助
解决方法
在分析了备选方案后,我通过以下方式解决了这个问题:
检查 DEBUG 条件指令仅为调试启用后:
我在所有引用 Microsoft.EntityFrameworkCore.Design 包的代码中使用了编译指令,以避免最终发布的程序集需要在输出目录中包含此包,并且因为发布处于release模式,代码被压制,像这样:
现在,应用程序按预期运行。
我遇到了一个 ASP.NET Core 6 网络应用程序的问题,该应用程序有多个项目,其中一些项目根据要求具有视图和控制器,因此我将它们标记为 <Project Sdk="Microsoft.NET.Sdk.Razor">
并添加Startup中的应用部分如下:
由于我 运行 基于 SQL 服务器数据库构建实体 类 的脚手架命令行,同时创建迁移文件,我使用一种技术来拥有实体singularized/pluralized 在设计时创建它们。为此,我必须使用 Microsoft.EntityFrameworkCore.Design 提供的 DesignTime 服务,方法是创建 DesignTimeDbContextFactory、DesignTimeServices 和 Pluralizer 类 提供数据库连接和多元化服务,所以我将 Microsoft.EntityFrameworkCore.Design 包添加到主项目和后端(dbcontext 存储库)项目.
为了避免这个包被复制到输出发布文件夹(这个包不应该是生产的一部分),我在引用包的项目的 csproj 中添加了以下配置,根据找到的互联网文档:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<!--<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
</PackageReference>
当我尝试通过 运行ning dotnet SicotX.dll 命令行(是主项目)运行 发布的项目时,问题就出现了。该应用尝试 运行 但什么都不做
我检查了我添加到应用程序的日志,这是堆栈跟踪列表:
2022-03-02T21:31:07.8101308-05:00 [INF] () Creating the web host ...
2022-03-02T21:31:09.0961070-05:00 [FTL] (Microsoft.AspNetCore.Hosting.Diagnostics) Application startup exception
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.get_Types()
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.<>c__DisplayClass11_0.<Subscribe>b__0()
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
at Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSource..ctor(ControllerActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory, OrderedEndpointsSequenceProvider orderSequence)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, String name, String pattern, Object defaults, Object constraints, Object dataTokens)
at SicotX.Startup.<>c.<Configure>b__6_2(IEndpointRouteBuilder endpoint) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 266
at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action`1 configure)
at SicotX.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory log) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 264
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
File name: 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
2022-03-02T21:31:09.6087813-05:00 [FTL] () A fatal error ocurred creating the web host.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.get_Types()
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFeatureProvider.PopulateFeature(IEnumerable`1 parts, ControllerFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetControllerTypes()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.<>c__DisplayClass11_0.<Subscribe>b__0()
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
at Microsoft.AspNetCore.Mvc.Routing.ControllerActionEndpointDataSource..ctor(ControllerActionEndpointDataSourceIdProvider dataSourceIdProvider, IActionDescriptorCollectionProvider actions, ActionEndpointFactory endpointFactory, OrderedEndpointsSequenceProvider orderSequence)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, String name, String pattern, Object defaults, Object constraints, Object dataTokens)
at SicotX.Startup.<>c.<Configure>b__6_2(IEndpointRouteBuilder endpoint) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 266
at Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action`1 configure)
at SicotX.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory log) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Startup.cs:line 264
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at SicotX.Program.Main(String[] args) in D:\Proyectos\Repositorios\Enterprise\.Net\SicotX\SicotX\Frontend\SicotX\Program.cs:line 47
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. El sistema no puede encontrar el archivo especificado.
File name: 'Microsoft.EntityFrameworkCore.Design, Version=6.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
我正在查看所有项目,看看是否有一些项目也引用了这个包,但只有主项目和后端项目被标记在 csproj 中,如上所述。
我正在尝试搜索问题是否由启动时加载的任何应用程序部分引起但没有成功。
重要提示:我的目标是避免 Microsoft.EntityFrameworkCore.Design 发布到生产环境,因为该包仅在设计时有效,并根据我一直在做的事情克服我面临的日志错误。
我在调试时没有遇到问题。
感谢任何帮助
解决方法
在分析了备选方案后,我通过以下方式解决了这个问题:
检查 DEBUG 条件指令仅为调试启用后:
我在所有引用 Microsoft.EntityFrameworkCore.Design 包的代码中使用了编译指令,以避免最终发布的程序集需要在输出目录中包含此包,并且因为发布处于release模式,代码被压制,像这样:
现在,应用程序按预期运行。