Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get Bundling/Minification to work in VS2012

I am using Visual Studio 2012 RC

I have created an ASP.NET 4 Web Application / Internet Application

In a view I have this code:

<script type="text/javascript">
  $(function () {
    alert("Test");
  });
</script>

In spite of prolonged searching I cannot get Bundling/Minification to work. In _Layout.cshtml I have the following. I have done NOTHING else. Can someone please tell me what I need to do? Many Thanks.

  @Styles.Render("~/Content/themes/base/css", "~/Content/css")
  @Scripts.Render("~/bundles/modernizr")

  @*This line Does Not Work*@
  @Scripts.Render("~/Scripts/js")

  @*This Line Does Work*@ 
  <script type="text/javascript" src="~/Scripts/jquery-1.7.2.js"></script>
like image 586
user1384117 Avatar asked Jun 07 '12 20:06

user1384117


1 Answers

First create your script bundle, and add whichever scripts you want.

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-1.*",
        "~/Scripts/jquery-ui-1.8.20.js"));
}

Then use @Scripts.Render in you page like this:

@Scripts.Render("~/bundles/jquery");

Notice that the path I specified in the ScriptBundle above is the same path I used in Scripts.Render.

Follow this article, http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification.

like image 91
Matthew Avatar answered Oct 20 '22 18:10

Matthew