我已经通过 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
最佳答案
由于最新版本显然存在依赖性问题,我不情愿地在 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/