c# - 无法加载文件或程序集 'WebGrease,版本 = 1.5.1.25624

标签 c# asp.net .net-4.0 visual-studio-2013 asp.net-4.0

我已经通过 NuGet 安装了 Microsoft ASP.NET Web 优化框架 1.1.3。我相信它安装得很好。这是一个 .NET 4.0 Web 窗体项目。

当我尝试捆绑时出现错误。我在 Application_Start 中的代码:

var jqueryBundle = new ScriptBundle("~/scripts/bundles/jquery");

    jqueryBundle.Include(new string[] { 
        "~/scripts/libs/jquery/jq/jquery-1.11.0.min.js",
        "~/scripts/swyft/mobileinit.min.js",
        "~/scripts/libs/jquery/jqm/142/lib/jquery.mobile-1.4.2.min.js",
    });

    BundleTable.Bundles.Add(jqueryBundle);

然后在我的一个 aspx 页面上...

<%= System.Web.Optimization.Scripts.Render("~/scripts/bundles/jquery") %>

给我这个错误:

An unexpected error has occurred. Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

但它就在那里!我正在运行 VS2013。

感谢您的帮助!

~红色

编辑 - 我的 WebConfig:

<runtime>
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
  ...
  <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
  </dependentAssembly>
  ...
</assemblyBinding>

编辑 - 无法安装 Web Grease 1.5.1:

当我尝试安装 Web Grease 1.5.1 时出现此错误:

You cannot call a method on a null-valued expression.
At L:\MY_PROJECT_PATH\packages\WebGrease.1.5.1\tools\install.ps1:45 char:5
+     $msbuild.Xml.AddProperty("WebGreaseLibPath", $relativePackageUri.ToString(). ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

** 编辑 - 添加 package.config 文件 **

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AjaxControlToolkit" version="7.1213" targetFramework="net40" />
<package id="AjaxMin" version="5.10.5260.16959" targetFramework="net40" />
<package id="Antlr" version="3.4.1.9004" targetFramework="net40" />
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net40" />
<package id="Microsoft.AspNet.ScriptManager.WebForms" version="5.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net40" />
<package id="Microsoft.Data.Edm" version="5.6.1" targetFramework="net40" />
<package id="Microsoft.Data.Services.Client" version="5.6.1" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
<package id="System.Spatial" version="5.6.1" targetFramework="net40" />
<package id="WebGrease" version="1.6.0" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="4.0.1" targetFramework="net40" />
</packages>

编辑 - 添加错误的 SS

Error Screenshot

最佳答案

由于最新版本显然存在依赖性问题,我不情愿地在 NuGet 包管理器控制台中使用这些命令回到旧版本的 Optimization 和 Webgrease:

Uninstall-Package Microsoft.AspNet.Web.Optimization
Uninstall-Package WebGrease
Install-Package Microsoft.AspNet.Web.Optimization -Version 1.1.0
Install-Package WebGrease -version 1.3

这个组合对我有用,但可能还有其他组合。

关于c# - 无法加载文件或程序集 'WebGrease,版本 = 1.5.1.25624,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23921550/

相关文章:

javascript - 呈现后的母版页控件 Id

c# - 遍历名称上具有不同数字的对象变量

c# - 如何 ContinueWith 前提的状态对象?

.net - 使用动态 OrderBy 进行分页/分页的 Linq 表达式

c# - 如何访问动态程序集中的匿名字段?

c# - 在 RowDataBound 中设置 OnClientClick 后事件未触发

c# - 无法从程序集“Microsoft.AspNetCore.Http,版本=3.1.0.0”中加载类型 'Microsoft.AspNetCore.Http.Internal.BufferingHelper'

c# - 在 asp.net c# 中重写 ToString(),基础知识。不起作用

c# - 从 ASP.NET 执行 SSIS 包时出错

asp.net - WCF Windows 身份验证如何在不显式设置凭据的情况下工作