发生未处理的exception:找不到包“Microsoft.Win32.Registry”的编译库位置

我正在使用asp.net核心2.0时,我build立我的泊坞窗的Web项目,并运行它作为一个容器,它抛出一个例外如下; 但当我在本地运行时没有任何问题。

基本上,在Docker构build之前,

  1. dotnet恢复
  2. dotnet构build
  3. dotnet发布

失败: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware [0]发生未处理的exception:找不到包' Microsoft.Win32.Registry '的编译库位置System.InvalidOperationException:找不到包' Microsoft.Win32.Registry '的编译库位置

这是我的.csproj文件

<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <TypeScriptToolsVersion>2.5</TypeScriptToolsVersion> <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish> <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish> <PreserveCompilationContext>true</PreserveCompilationContext> </PropertyGroup> <PropertyGroup> <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> <!--<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>--> </PropertyGroup> <ItemGroup> <None Update="Dockerfile"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <ItemGroup> <Content Update="appsettings.json" CopyToOutputDirectory="Always" /> <Content Update="Views\**\*" CopyToOutputDirectory="Always" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" /> <PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.1" /> <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" /> <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.1" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> </ItemGroup> <ItemGroup Label="Embedded Resources"> <EmbeddedResource Include="Views\**\*.cshtml" /> </ItemGroup> <ItemGroup> <None Include="wwwroot\app.component.js" /> <None Include="wwwroot\app.component.js.map" /> <None Include="wwwroot\app.component.ts" /> <None Include="wwwroot\app.module.js" /> <None Include="wwwroot\app.module.js.map" /> <None Include="wwwroot\app.module.ts" /> <None Include="wwwroot\app.routing.js" /> <None Include="wwwroot\app.routing.js.map" /> <None Include="wwwroot\app.routing.ts" /> <None Include="wwwroot\Components\Home.component.js" /> <None Include="wwwroot\Components\Home.component.js.map" /> <None Include="wwwroot\Components\Home.component.ts" /> <None Include="wwwroot\Components\inzmotivation.component.html" /> <None Include="wwwroot\Components\inzmotivation.component.ts" /> <None Include="wwwroot\js\system.config.js" /> <None Include="wwwroot\main.js" /> <None Include="wwwroot\main.js.map" /> <None Include="wwwroot\main.ts" /> <None Include="wwwroot\Model\InzMotivation.ts" /> <None Include="wwwroot\Service\inzmotivations.service.ts" /> <None Include="wwwroot\shared\enum.ts" /> <None Include="wwwroot\shared\global.js" /> <None Include="wwwroot\shared\global.js.map" /> <None Include="wwwroot\shared\global.ts" /> </ItemGroup> <ItemGroup> <TypeScriptCompile Include="wwwroot\Components\inzmotivation.component.ts" /> <TypeScriptCompile Include="wwwroot\Model\InzMotivation.ts" /> <TypeScriptCompile Include="wwwroot\polyfills.ts" /> <TypeScriptCompile Include="wwwroot\Service\inzmotivations.service.ts" /> </ItemGroup> <ItemGroup> <Folder Include="k8config\" /> </ItemGroup> </Project> 

Startup.cs:

  public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddOptions(); // Add framework services. services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } } } 

Program.cs中

 public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>() .UseUrls("http://*:8181") .UseApplicationInsights() .Build(); } 

    Interesting Posts