asp.net-mvc System.Web.Optimization 和 Microsoft.Web.Optimization 不会在 vs 2012 中加载引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16179293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.Web.Optimization and Microsoft.Web.Optimization won't load reference in vs 2012
提问by MacSalty
I'm working on an MVC 4 project started in Visual Studio 2010. Right now I'm working on a machine with Visual Studio 2012 as I don't have access to the machine I was originally working on. I tried all morning to find answers, but they don't seem to help my situation.
我正在处理一个在 Visual Studio 2010 中启动的 MVC 4 项目。现在我正在使用 Visual Studio 2012 的机器上工作,因为我无法访问我最初使用的机器。我整个上午都在努力寻找答案,但它们似乎对我的情况没有帮助。
I followed How to add reference to System.Web.Optimization for MVC-3-converted-to-4 appand installed from nuget right into my solution. Even though I have all the required reference packages downloaded and installed on my machine, System.Web.Optimizationcontinues to remain missing. Is there anything else I can do?
我遵循了如何为 MVC-3-converted-to-4 应用程序添加对 System.Web.Optimization 的引用,并从 nuget 直接安装到我的解决方案中。尽管我已经在我的机器上下载并安装了所有必需的参考包,但System.Web.Optimization仍然缺少。还有什么我可以做的吗?
Edit: When I try to build the project I receive the following errors
编辑:当我尝试构建项目时,我收到以下错误
- The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) - BundleConfig.cs
- The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) - Global.asax.cs
- The type or namespace 'BundleCollection' could not be found (are you missing a using directive or an assembly reference?) - BundleConfig.cs
- 命名空间“System.Web”中不存在类型或命名空间名称“Optimization”(您是否缺少程序集引用?)- BundleConfig.cs
- 命名空间“System.Web”中不存在类型或命名空间名称“优化”(您是否缺少程序集引用?)- Global.asax.cs
- 找不到类型或命名空间“BundleCollection”(您是否缺少 using 指令或程序集引用?)- BundleConfig.cs
My BundleConfig.cs contains
我的 BundleConfig.cs 包含
using System.Web;
using System.Web.Optimization;
namespace BCCDC_AdminTool
{
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/? LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
}
采纳答案by sdagkas
This is a long shot but here it goes anyway, right click on the project --> Property Pages and make sure System.Web.Optimization entry exists. If not, copy the System.Web.Optimization.dll to your bin folder or import it as a reference.
这是一个很长的镜头,但无论如何,右键单击项目 --> 属性页并确保 System.Web.Optimization 条目存在。如果没有,请将 System.Web.Optimization.dll 复制到您的 bin 文件夹或将其导入作为参考。
Edit: mvc projects don't have the "Property pages" menu option.
编辑:mvc 项目没有“属性页”菜单选项。
One other thing you can try is create a new mvc4 basic project, go to the bin folder of the solution and copy the System.Web.Optimization.dll to the bin folder of your other project that is giving you the error. If you can't find the dll then try updating the nuget packages.
您可以尝试的另一件事是创建一个新的 mvc4 基本项目,转到解决方案的 bin 文件夹并将 System.Web.Optimization.dll 复制到其他项目的 bin 文件夹中,该文件夹为您提供了错误信息。如果找不到 dll,请尝试更新 nuget 包。
回答by Jonathan Bick
I had the same problem with a VS2010 project I opened in VS2012. The Microsoft.AspNet.Web.Optimization package was missing so I just needed to download it using Nuget Package Manager.
我在 VS2012 中打开的 VS2010 项目遇到了同样的问题。缺少 Microsoft.AspNet.Web.Optimization 包,所以我只需要使用 Nuget 包管理器下载它。
You can run in the console: Install-Package Microsoft.AspNet.Web.Optimization
您可以在控制台中运行: Install-Package Microsoft.AspNet.Web.Optimization
回答by rido
I know it's confusing, but you will need to Install-Package Microsoft.AspNet.Web.Optimization
我知道这很令人困惑,但你需要 Install-Package Microsoft.AspNet.Web.Optimization
回答by Bryan Legend
Try going to the web.config in the Views folder and removing the following line:
尝试转到 Views 文件夹中的 web.config 并删除以下行:
<add namespace="System.Web.Optimization" />
That fixed it for me.
那为我修好了。
回答by rakhesh
Go to tools >> Library Package Manager >> Manage Nuget Packages >> install Microsoft ASP.NET web optimisation framework
转到工具 >> 库包管理器 >> 管理 Nuget 包 >> 安装 Microsoft ASP.NET Web 优化框架
回答by sming
I battled this for an hour and none of the above suggestions worked. In the end only the following worked (for some obtuse reason) :
我为此奋斗了一个小时,但上述建议均无效。最后只有以下工作(出于某种迟钝的原因):
- ctrl-q -> type "package manager console"
Uninstall-Package Microsoft.AspNet.Web.Optimization <problem project name>Install-Package Microsoft.AspNet.Web.Optimization <problem project name>
- ctrl-q -> 输入“包管理器控制台”
Uninstall-Package Microsoft.AspNet.Web.Optimization <problem project name>Install-Package Microsoft.AspNet.Web.Optimization <problem project name>
WARNING/HEADS-UP
警告/注意事项
- the above will install the latest version of
Microsoft.AspNet.Web.Optimization. If you want a particular version (say v1.1.1), useInstall-Package Microsoft.AspNet.Web.Optimization <problem project name> -Version 1.1.1 - don't forget the
<problem project name>parameter or nuget will operate at the Solution-level, possibly trampling sibling projects. - Note that omitting the project name is an of itself really handy for doing Solution-level version updates or package installs.
- 以上将安装最新版本的
Microsoft.AspNet.Web.Optimization. 如果您想要特定版本(例如 v1.1.1),请使用Install-Package Microsoft.AspNet.Web.Optimization <problem project name> -Version 1.1.1 - 不要忘记
<problem project name>参数,否则 nuget 将在解决方案级别运行,可能会践踏同级项目。 - 请注意,省略项目名称本身对于执行解决方案级别的版本更新或包安装非常方便。
回答by Bravax
Uninstalling, and reinstalling the Microsoft.AspNet.Web.Optimization package solved it for me.
卸载并重新安装 Microsoft.AspNet.Web.Optimization 包为我解决了这个问题。
回答by Faisal
Reinstalling system.web.optimizaiton using Nuget package manager solved this issue for me..
使用 Nuget 包管理器重新安装 system.web.optimizaiton 为我解决了这个问题..
回答by Aman Agarwal
Simple Solution. Open Visual Studio in administrator mode. It will resolve your error.
简单的解决方案。以管理员模式打开 Visual Studio。它将解决您的错误。
回答by BornToCode
What worked for me in a specific scenario (I downloaded a MVC project from source control and received that error), was to open a new MVC project on the same solution. Afterwards I could delete the new project I've created and it still works (on VS2012).
在特定情况下(我从源代码管理下载一个 MVC 项目并收到该错误)对我有用的是在同一解决方案上打开一个新的 MVC 项目。之后我可以删除我创建的新项目,它仍然有效(在 VS2012 上)。

