发生了未处理的异常:找不到包的编译库位置' Microsoft.Win32.Registry'

时间:2017-11-21 16:17:22

标签: c# docker exception asp.net-core-mvc

当我构建我的weber项目为docker并将其作为容器运行时,我使用asp.net core 2.0,如下所示抛出异常;但是当我在当地运行它时没有任何问题。

我基本上做了,之后是docker build;

  1. dotnet restore
  2. dotnet build
  3. dotnet publish
  4.   

    失败:    Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware [0]         发生了未处理的异常:找不到包的编译库位置' 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();
    }
    

0 个答案:

没有答案