I'm using asp.net core 2.0 when i build to my web project for docker and run it as a container its throw an exception as below; but no any problem when i run it on local.
I did basically, before then docker build;
- dotnet restore
- dotnet build
- dotnet publish
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0] An unhandled exception has occurred: Cannot find compilation library location for package 'Microsoft.Win32.Registry' System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.Win32.Registry'
This is my .csproj file :
<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();
}