可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
While upgrading WebGrease
to version 1.3.0
gets me error:
Could not load file or assembly 'WebGrease, Version=1.0.0.0, 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)
Source Error:
Line 6: <title>@ViewBag.Title</title>
Line 7: @Styles.Render("~/Content/bundles/bootstrap")
How to resolve this error.
回答1:
Here is the answer that has worked for me, and it is a combination of some of the above answers.
First install / uninstall / reinstall the following packages:
Install-Package Microsoft.AspNet.Web.Optimization
Update-Package WebGrease
Uninstall-Package Microsoft.AspNet.Web.Optimization
Uninstall-Package WebGrease
Install-Package Microsoft.AspNet.Web.Optimization
Update-Package WebGrease
Then make a copy of the contents of ~/Views/Shared/_Layout.cshtml
delete the _Layout.cshtml file, recreate it and paste the contents back in.
this is the final fix that has worked for me.
回答2:
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" /> </dependentAssembly>
Change the upper code in Web.config
to the following
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0"/> </dependentAssembly>
回答3:
It looks like you have reference to older (1.0.0.0?) version of assembly (assuming current version is 1.3.0.0). In this case you need assembly redirect in web.config or better yet recompile your binaries to use latest version.
Another possiblity if latest version shares the same assembly version as old one (1.0.0.0) you need to recompile your code to use the right assembly and make sure correct copy is used (check GAC for wrong one, use fuslogv to investigate what exact file caused the error).
回答4:
I had the same issue. Another developer upgraded the WebGrease package (as well as others), but something didn't sync or get checked in. I edited the package file to remove the references to the existing package. Then I reinstalled via Package Manager. Finally, I updated the packages.
It seems as though packages won't install or update if the packages.config file does not match the files (including proper versions) in your project. No error is given in the Package Manager though, it just fails to update or install packages.
回答5:
A combination of the following resolved the issue for me. First, running the following commands on the Package Manager command line (similar to the answer provided by sec_goat, but not exactly the same):
Uninstall-Package Microsoft.AspNet.Web.Optimization
Uninstall-Package WebGrease
Install-Package Microsoft.AspNet.Web.Optimization
Update-Package WebGrease
Then, similar to Hriju, I needed to change this line in my web.config:
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
into this:
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" />
回答6:
The binding redirect that worked for me:
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.3.0.0"/> </dependentAssembly>
</assemblyBinding>
subtle difference is i didn't include this version (1.3.0.0) in the oldVersion
attr.
fail cake!
回答7:
I had a similar issue except it wasn't an error but a warning. After updating WebGrease to 1.3.0, a build put the warning source on the declaration. After ensuring that I had the appropriate assembly redirect in my web.config file, I eventually created a new _Layout.cshtml view and saved over the old file with the exact same razor markup as was in the previous (copy/paste). After that, the warning went away.
I'm not exactly sure what the warning was all about but try copying your code in your file, pasting it into a new file and overwriting the original.
If anyone has any insight as to why this works, I'm all ears.
回答8:
It's a problem with Microsoft.AspNet.Web.Optimization (Optimise moving forward).
You need to downgrade WebGrease by uninstalling Optimise and removing any WebGrease assembly redirects from web.config.
Then reinstall Optimise and make sure you don't upgrade WebGrease.
It's a quick fix but it got my build working!
回答9:
For a Web API project I'm working on what really worked was the following:
Open NuGet package manager, click in Installed packages
and then uninstall Microsoft.AspNet.Web.Optimization
. It prompts it'll remove WebGrease 1.1.0
. Hit Yes
.
Now reinstall it clicking NuGet's Online tab and search for Microsoft.AspNet.Web.Optimization
.
Now everything is working as expected.
回答10:
Thanks to @roadsunknown. My configuration got hosed after my host machine froze, thus causing my VM to not shutdown properly. To resolve this I uninstalled Microsoft.AspNet.Web.Optimization through NuGet, then had to remove the reference to WebGrease in packages.config, and finally reinstalled Microsoft.AspNet.Web.Optimization through NuGet.
回答11:
To fix this, all i did was to Update the package.config file (WEBMATRIX)
<packages>
<package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
<package id="WebGrease" version="1.3.0" targetFramework="net40" />
</packages>
Cheers!!!
回答12:
This is what my runtime section looks like and it works
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
回答13:
Same deal as Hriju and Nathan (Uninstall, re-install and update), only instead of omitting the newVersion
attribute, I kept it. But since WebGrease went from 1.1.0 straight to 1.3.0, there was no need for 1.2.0 (as jenson-button-event had it) (Good luck to JB in Spain, btw).
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.3.0.0" />
Pedantic? Maybe, but it's always in the details, right? This fixed it for me.
Anyhow, here's to hoping they do it right on the next update.
回答14:
In my case all this methods didn't work. Finally I resolve this problem by uninstalling Microsoft.AspNet.Web.Optimization and WebGrease Packages via Package Manager, then I open my project file (.csproj) in notepad and delete all entries related to this two Packages, turn outs that there was problem. Finally I install this two packages via package manager again and run project. All work's fine now.