css - asp.net budle.config 不包括新的 css 文件

标签 css asp.net bundle

我有问题,在我的 budle.config 文件中我添加了一些具有正确路径的 css 文件,我也重建了解决方案,但它不包括页面中的任何新文件。

<?xml version="1.0" encoding="utf-8" ?>
<bundles version="1.0">
  <styleBundle path="~/Content/css">
    <include path="~/Content/bootstrap.css" />
    <include path="~/Content/style.css" />
    <include path="~/fonts/fontawesome/fontawesome.css" />
  </styleBundle>
</bundles>

我原来的基本样式名称是 style.css 和一些其他字体文件,但它不起作用。我看到很多解决方案说它不支持 .min.css 文件,所以我也删除了它,但仍然没有用。

最佳答案

  1. 使用 BundleConfig 类和 RegisterBundles 方法:

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using System.Web.Optimization;
    
        namespace Core
        {
            public class BundleConfig
            {            
                public static void RegisterBundles(BundleCollection bundles)
                {
    
                    bundles.Add(new StyleBundle("~/Content/css").Include(
                         "~/Content/css/bootstrap.css",
                        "~/Content/css/style.css",
                        "~/Content/css/font-awesome.css"                                       
                    ));
                }
            }
        }
    
  2. _Layout.cshtmlhead 中写入:

     <head>
            @System.Web.Optimization.Styles.Render("~/Content/css")
     </head>
    
  3. Application_Start() 中调用 RegisterBundles :

     BundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);
    

关于css - asp.net budle.config 不包括新的 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43697390/

相关文章:

asp.net - 如何在不使用 Membership.GetUser() 的情况下访问 ASP.NET Membership 中的 UserId?

asp.net - Redis 中的 Azure 缓存/DataCache 样式区域

asp.net-mvc-4 - 如何最好地从 Nuget 写入 BundleConfig

html - 绝对定位的 child 忽略了相对 parent

jquery - 使用导航箭头制作幻灯片

javascript - 在 JavaScript 中使用变量更改 CSS 中的高度

ios - 更改应用程序名称后更改了包标识符

jquery - 如何通过 jquery 或其他类型修改 iframe 中的 css?

c# - Console.WriteLine 在 ASP.net 生产环境中去哪里?

angular - 在 Angular 应用程序中动态包含另一个 webpack 包