簡體   English   中英

System.Web.Razor.dll未復制到bin文件夾

[英]System.Web.Razor.dll not copied to bin folder

問題

我們有一個ASP.Net 5.2.3項目,我們正在嘗試升級到.NET 4.6。

運行時,我們收到錯誤消息

無法加載文件或程序集'System.Web.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依賴項之一。 該系統找不到指定的文件。

請注意,我們從NuGet安裝了Microsoft.AspNet.Razor版本3.2.3,但錯誤消息是指版本3.0.0.0。

現在,如果我手動復制

包\\ Microsoft.AspNet.Razor.3.2.3 \\ LIB \\ net45 \\ System.Web.Razor.dll

TheWebProject \\ BIN

該項目運行得很好。

GAC

請注意,有兩個條目

C:\\ WINDOWS \\ Microsoft.NET \\裝配\\ GAC_MSIL \\ System.Web.Razor

v4.0_1.0.0.0__31bf3856ad364e35

v4.0_2.0.0.0__31bf3856ad364e35

我知道GAC存在的 DLL會忽略CopyLocal = True 但是,我不明白為什么該項目無法解析GAC的引用,並且不願意將使用NuGet引用的版本復制到bin文件夾。

web.config中

我們在web.config中有以下綁定重定向,大概是由NuGet安裝程序放在那里

  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>

我們還嘗試設置newVersion =“3.2.3.0”以匹配NuGet包管理器中顯示的版本。 當我們改變這兩者時

<bindingRedirect oldVersion="0.0.0.0-3.2.3.0" newVersion="3.2.3.0" />

我們得到一個稍微不同的錯誤

無法加載文件或程序集“System.Web.WebPages.Razor”或其依賴項之一。 定位的程序集的清單定義與程序集引用不匹配。 (HRESULT異常:0x80131040)

如何設置項目引用來解決此問題?

嘗試右鍵單擊引用列表中的引用,並將“Copy Local”設置為“True”。

我懷疑,您的配置強制它為3.0.0.0。 嘗試這個:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <bindingRedirect oldVersion="3.0.0.0" newVersion="3.2.3.0" />
      </dependentAssembly>      
    </assemblyBinding>
  </runtime>

您需要將程序集重定向添加到* .config文件中。 打開包管理器控制台並輸入以下命令: Add-BindingRedirect [-ProjectName]

參考: http//weblog.west-wind.com/posts/2014/Nov/29/Updating-Assembly-Redirects-with-NuGethttps://docs.nuget.org/consume/package-manager-console- PowerShell的參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM