将捆绑包添加到现有 ASP.NET Webforms 解决方案
Adding Bundles to existing ASP.NET Webforms solution
我正在尝试将捆绑包添加到现有的 ASP.NET Webforms 解决方案,但我的捆绑包总是呈现为空,我不确定为什么。我一直在关注 this blog post.
到目前为止我有:
- 添加了 Microsoft ASP.NET Web 优化框架 NuGet 包
- 确保包含所需的参考资料
- 尝试在 Web.config
中使用 debug="false" 和 debug="true"
- 在我的解决方案中添加了以下代码
Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
App_Start/BundleConfig.cs
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/Global").Include(
"~/js/jquery-{version}.js",
"~/js/jquery-ui.js"));
bundles.Add(new ScriptBundle("~/bundles/GlobalHead").Include(
"~/js/modernizr*"));
bundles.Add(new StyleBundle("~/Content/Global").Include(
"~/css/site.css"));
}
}
Site.Master
<head runat="server">
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundle/GlobalHead") %>
<%: Styles.Render("~/Content/Global") %>
</asp:PlaceHolder>
</head>
<body>
<%: Scripts.Render("~/bundle/Global") %>
</body>
Web.Config
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
更新
明确地说,当我打开网页并使用 chrome 开发工具检查资源时,我可以看到
Content/Site.css
bundle/Global.js
bundle/GlobalHead.js
但是检查的时候没有内容
简单的解决方案,我有一些输入错误。
在 Site.Master 中,我错过了捆绑包末尾的 's'。让我的 Site.Master 看起来像这样。
<head runat="server">
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/GlobalHead") %>
<%: Styles.Render("~/Content/Global") %>
</asp:PlaceHolder>
</head>
<body>
<%: Scripts.Render("~/bundles/Global") %>
</body>
我正在尝试将捆绑包添加到现有的 ASP.NET Webforms 解决方案,但我的捆绑包总是呈现为空,我不确定为什么。我一直在关注 this blog post.
到目前为止我有:
- 添加了 Microsoft ASP.NET Web 优化框架 NuGet 包
- 确保包含所需的参考资料
- 尝试在 Web.config 中使用 debug="false" 和 debug="true"
- 在我的解决方案中添加了以下代码
Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
App_Start/BundleConfig.cs
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/Global").Include(
"~/js/jquery-{version}.js",
"~/js/jquery-ui.js"));
bundles.Add(new ScriptBundle("~/bundles/GlobalHead").Include(
"~/js/modernizr*"));
bundles.Add(new StyleBundle("~/Content/Global").Include(
"~/css/site.css"));
}
}
Site.Master
<head runat="server">
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundle/GlobalHead") %>
<%: Styles.Render("~/Content/Global") %>
</asp:PlaceHolder>
</head>
<body>
<%: Scripts.Render("~/bundle/Global") %>
</body>
Web.Config
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
更新
明确地说,当我打开网页并使用 chrome 开发工具检查资源时,我可以看到
Content/Site.css
bundle/Global.js
bundle/GlobalHead.js
但是检查的时候没有内容
简单的解决方案,我有一些输入错误。
在 Site.Master 中,我错过了捆绑包末尾的 's'。让我的 Site.Master 看起来像这样。
<head runat="server">
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/GlobalHead") %>
<%: Styles.Render("~/Content/Global") %>
</asp:PlaceHolder>
</head>
<body>
<%: Scripts.Render("~/bundles/Global") %>
</body>