[英]Kestrel with IIS - libuv.dll missing on run
我們正在設置現有的Web API服務器,以便與現有API一起提供站點。 我一直在松散地閱讀這篇文章 。
這是我的Global.asax.cs的樣子:
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();
}
}
和Startup.cs:
public partial class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseDefaultFiles();
app.UseStaticFiles();
}
}
當我運行項目時,我收到錯誤
無法加載DLL“libuv”:找不到指定的模塊。 (來自HRESULT的異常:0x8007007E)
libuv是Kestrel的依賴。 如果我手動將它從packages文件夾復制到bin文件夾,它可以工作。 這個GitHub問題評論似乎有意義。 現在project.json正在被移走,我怎樣才能讓它自動復制?
有些人認為它不知道是否使用32位或64位版本的libuv,因為平台在項目屬性中設置為Any CPU。 我已嘗試在解決方案和項目設置中將其設置為x64,問題仍然存在。
如何自動將libuv.dll直接復制到構建目錄?
我不考慮在項目中包含該文件(而不是在packages文件夾中)並將其設置為復制到輸出目錄的真正解決方案,只是一種解決方法。 我希望找到解決方案,而不是解決方法。
我在遷移項目之前遇到過類似的問題。 Visual Studio可能會因項目不匹配而行為不端。
簡單回答:您需要將項目更改為MSBuild / csproj格式。
首先,如果您嘗試在解決方案中使用.NET Core,請在Visual Studio中右鍵單擊您的項目, 如果您沒有看到Edit xxxxxx.csproj
那么您可能會Edit xxxxxx.csproj
問題就像你上面報道的一樣。
基本上,.NET Core項目模板在編譯項目時使用不同的工具。
下面的解決方案是一種通用方法,可以解決幾乎所有與嘗試以.NET Core為目標的項目相關的問題,但希望使用其他框架中的庫。 到目前為止,還沒有一個很好的工具來解決這個問題,所以你將不得不采用手動模式。
解決方案非常簡單(但有點單調乏味)。
創建一個新項目,然后選擇“.NET Core”。
幾乎在所有情況下,您可能都希望避免使用ASP.NET核心Web應用程序模板,但這可以用於另一個討論。
右鍵單擊該項目,然后選擇“ 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>
選擇一個您想要定位的框架,並確保它是受支持的(這是一個表格)。
我在上面的代碼片段中使用了net452
作為示例。 您可以在此處找到有關命名的更多信息。
您將不得不為解決方案中的每個項目執行此操作,以防止Visual Studio出現意外行為。
關於如何讓ASP.NET Core與舊框架配合良好,網上真的沒什么用。 希望這會幫助你。 我希望我早些時候對自己有這個建議。
我只是將nuget包安裝到我的項目中並重新部署。
Install-Package Libuv -Version 1.10.0
試試這個 - 它可以解決你的問題:
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();
寫下這些代碼:
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已經整合了這條管道,就像一個魅力。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.