Kestrel with IIS - libuv.dll missing on run

女生的网名这么多〃 提交于 2019-12-08 14:42:18

问题


We're setting up an existing Web API server to serve site(s) alongside an existing API. I have been loosely following this article.

Here's what my Global.asax.cs looks like:

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        AutoMapperConfig.RegisterMappings();

        var host = new WebHostBuilder()
           .UseKestrel()
           .UseWebRoot("wwwroot")
           .UseIISIntegration()
           .UseStartup<Startup>()
           .Build();

        host.Run();
    }
}

and Startup.cs:

public partial class Startup
{
    public void Configure(IApplicationBuilder app)
    {
        app.UseDefaultFiles();
        app.UseStaticFiles();
    }
}

When I run the project, I get the error

Unable to load DLL 'libuv': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

libuv is a dependency of Kestrel. If I manually copy it from the packages folder to the bin folder, it works. That seems to make sense with this GitHub Issue comment. Now that project.json is being moved away from, how can I get it to copy automatically?

Some have posited that it does not know whether to use 32 or 64 bit version of libuv because the Platform is set to Any CPU in the project properties. I have tried setting it to x64 in both the solution and project settings and the problem persists.

How can I make libuv.dll copy directly to the build directory automatically?

I do not consider including the file in the project (instead of in the packages folder) and setting it to copy to the output directory a real solution, only a workaround. I'm hoping to find a solution, not a workaround.


回答1:


I've had a similar problem before when migrating projects. Visual Studio may misbehave a lot with mismatched projects.

Simple Answer: You need to change your projects to the MSBuild/csproj format.

To start with, if you are trying to use .NET Core in your solution, then right-click your project(s) in Visual Studio, and if you don't see Edit xxxxxx.csproj then you're likely going to have issues like the one you are reporting above.

Basically, the .NET Core project templates uses different tooling when compiling the project.

The solution below is a generic way to solve almost all issues regarding projects that try to target .NET Core, but wish to use libraries from another framework. There isn't a good tool (so far) to bridge this problem, so you're going to have to go manual-mode.


Let's get started.

The solution is quite simple (but it's a bit tedious).

Step 1: Make a new project using the new MSBuild/csproj format

Create a new project, and select ".NET Core".

In almost all cases, you probably want to avoid using the ASP.NET Core Web Application template, but that's for another discussion all together.

Step 2: Target the correct framework

Right-click the project and select Edit xxxxxx.csproj

<PropertyGroup>
    <TargetFramework>net452</TargetFramework>
    <!--you will also probably want to note that you need these for a console app -->
    <OutputType>Exe</OutputType>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>

Pick a framework you want to target, and make sure that it's supported (here is a table).
I have used net452 in the above code snippet for an example. You can find out more about the naming here.

Step 3. Repeat for all projects.

You're going to have to do this for every project in your solution to keep Visual Studio from behaving unexpectedly.

There really isn't much online about how to get ASP.NET Core to work well with old frameworks. Hopefully this will help you out. I wish I had this advice earlier on myself.




回答2:


I just install nuget package to my project and redeploy.

Install-Package Libuv -Version 1.10.0




回答3:


Try this - it could solve your problem:

var host = new WebHostBuilder()
            .UseKestrel()
            // .UseWebRoot("wwwroot") keep it if you need it
            .UseContentRoot(Directory.GetCurrentDirectory()) // this could solve your problem
            // .UseUrls("http://0.0.0.0:5000") use this if you're using nginx
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();



回答4:


Write these codes:

using Microsoft.Owin;
using Owin;
using System.Web.Http;

[assembly: OwinStartup(typeof(WebApiAndStaticFiles.OwinStartup))]

namespace WebApiAndStaticFiles
{
    public class OwinStartup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseDefaultFiles();
            app.UseStaticFiles();

            HttpConfiguration webApiConfiguration = new HttpConfiguration();
            GlobalConfiguration.Configure(webApiConfiguration); // Instead of GlobalConfiguration.Configure(WebApiConfig.Register);
            app.UseWebApi(webApiConfiguration);

        }
    }
}

and install these nuget packages:

<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net462" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net462" />
  <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net462" />
  <package id="Microsoft.Owin" version="3.1.0" targetFramework="net462" />
  <package id="Microsoft.Owin.FileSystems" version="3.1.0" targetFramework="net462" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="3.1.0" targetFramework="net462" />
  <package id="Microsoft.Owin.StaticFiles" version="3.1.0" targetFramework="net462" />
  <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net462" />
  <package id="Owin" version="1.0" targetFramework="net462" />

You can't simply use asp.net core pipelines inside asp.net/iis hosted app pipeline. But Owin has integration for that pipeline which works like a charm.



来源:https://stackoverflow.com/questions/44143537/kestrel-with-iis-libuv-dll-missing-on-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!