gpt4 book ai didi

c# - BundleConfig.cs 没有引用任何内容?

转载 作者:行者123 更新时间:2023-12-02 13:25:11 24 4
gpt4 key购买 nike

首先,我请大家耐心等待,因为我对 ASP 和 C# 总体来说还是个新手,而且我可能没有像我希望的那样形成大多数概念。

我在使用 BundleConfig.cs 时遇到一些问题。显然它尝试引用的每个模块都不起作用,或者找不到?

这是我得到的 BundleConfig:

using System.Web;
using System.Web.Optimization;

namespace WebApplication
{
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.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"));
}
}
}

这就是我在 _Layouyt.cshtml 中引用的内容

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
@Styles.Render("~/Content/site.css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/Scripts/jquery.validate.min.js")
@Styles.Render("~/Content/bootstrap.min.css")
@Styles.Render("~/Content/layoutsheet.css")
</head>
<body>
....
</body>
</html>

根据 Google Chrome 提供的开发者工具,它现在根本没有引用任何内容:

No references?

我真的不知道该怎么办。我注意到该 bundle 引用了我的解决方案资源管理器未显示的某些内容,例如没有/css 文件夹。我一直在搞乱它,没有任何结果或引用。

如果您好奇,这是我现在的解决方案资源管理器(我想它显示了您可能感兴趣的部分):

Solution Explorer

您知道为什么会发生这种情况吗?

最佳答案

您需要在应用程序启动时使用 System.Web.Optimization 程序集中的 BundleConfig.RegisterBundles(BundleTable.Bundles); 向应用程序注册 bundle 。

可以将其放置在 global.asax 文件中的 Application_Start() 方法中。

捆绑配置是一种配置要组合和缩小的文件的方法,默认情况下,当使用发布构建配置构建应用程序时会发生这种情况。因此,配置中传递的 URL 并不指向解决方案中的文件,而是提供在运行时捆绑和缩小的文件的端点。

一个好的起点是 bundling and minification article在 asp.net 网站上。

关于c# - BundleConfig.cs 没有引用任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26050914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com