C# 运行时缺少IIS-libuv.dll的Kestrel
我们正在设置一个现有的Web API服务器,以便与现有的API一起为站点提供服务。我一直在松散地跟随 下面是my Global.asax.cs的外观:C# 运行时缺少IIS-libuv.dll的Kestrel,c#,asp.net,asp.net-web-api,kestrel-http-server,C#,Asp.net,Asp.net Web Api,Kestrel Http Server,我们正在设置一个现有的Web API服务器,以便与现有的API一起为站点提供服务。我一直在松散地跟随 下面是my Global.asax.cs的外观: public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfigur
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();
}
}
当我运行项目时,我得到了错误
无法加载DLL“libuv”:找不到指定的模块。(来自HRESULT的异常:0x8007007E)
libuv是Kestrel的一个依赖项。如果我手动将它从packages文件夹复制到bin文件夹,它就会工作。这似乎是有道理的。既然project.json已从中移除,我如何让它自动复制
一些人认为它不知道是使用32位还是64位版本的libuv,因为平台在项目属性中设置为任何CPU。我尝试在解决方案和项目设置中将其设置为x64,但问题仍然存在
如何使libuv.dll直接自动复制到生成目录?
我不考虑将文件包含在项目中(而不是在包文件夹中),并将其设置为复制到输出目录的真正解决方案,只是一个解决方案。我希望找到一个解决方案,而不是解决办法。
试试这个-它可以解决您的问题: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();
var host=new WebHostBuilder()
.UseKestrel()
//.UseWebRoot(“wwwroot”)如果需要,请保留它
.UseContentRoot(Directory.GetCurrentDirectory())//这可以解决您的问题
//.useURL(“http://0.0.0.0:5000)如果您正在使用nginx,请使用此选项
.Useii整合()
.UseStartup()
.Build();
我以前在迁移项目时也遇到过类似的问题。VisualStudio在处理不匹配的项目时可能会出现很多错误行为
简单回答:您需要将项目更改为MSBuild/csproj格式。
首先,如果您试图在解决方案中使用.NET Core,请在Visual Studio中右键单击您的项目,如果您没有看到编辑xxxxxx.csproj
,则您可能会遇到类似上面报告的问题。
基本上,.NET核心项目模板在编译项目时使用不同的工具
下面的解决方案是一种通用方法,可以解决几乎所有与试图以.NETCore为目标,但希望使用其他框架中的库的项目相关的问题。到目前为止,还没有一个好的工具来解决这个问题,所以您必须进入手动模式
让我们开始吧。 解决方案很简单(但有点乏味) 步骤1:使用新的MSBuild/csproj格式创建新项目 创建一个新项目,然后选择“.NET Core” 在几乎所有情况下,您可能都希望避免使用ASP.NET核心Web应用程序模板,但这只是另一个讨论 步骤2:针对正确的框架 右键单击项目并选择编辑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>
net452
Exe
win7-x64
选择一个您想要定位的框架,并确保它受支持(这是一个表)。我在上面的代码片段中使用了
net452
。你可以了解更多关于这个项目的信息
第三步。对所有项目重复此操作。
您必须对解决方案中的每个项目都执行此操作,以防止VisualStudio出现意外行为
关于如何让ASP.NETCore与旧框架很好地协同工作,在线上的内容并不多。希望这能帮到你。但愿我能早点得到这个建议。写下以下代码:
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);
}
}
}
并安装以下nuget软件包:
<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" />
您不能简单地在asp.net/iis托管的应用程序管道中使用asp.net核心管道。但是Owin对管道进行了集成,这很有吸引力。我只是将nuget软件包安装到我的项目中,然后重新部署
安装程序包Libuv-Version 1.10.0您真的要在System.Web项目中运行ASP.NET核心站点吗?为什么?@davidfoll不,我只是想从一个Web API项目中提供静态文件。一个ASP.NET核心Web API项目?@davidfoll对。为什么不将其作为控制台应用程序与IIS集成运行?这就是ASP.NET核心项目的使用方式。为什么要在System.Web.HttpApplication中托管它?对所有项目重复此操作?使用.NETCore和完整框架从头开始创建新项目?或者只是为每个项目创建一个新的项目文件?
<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" />