Reputation: 892
Current Project:
I recently had to rebuild my entire project from scratch (nuking from orbit, creating new project, and moving over all prior-edited/created files by hand into the new project), but this issue was present even in the old project. So I’m pretty sure it isn’t anything I am doing directly.
The key thing is, I am currently working in Debug mode. Yes, I know, I need to eventually move to Release mode, but I am having problems even when working directly through Visual Studio.
My jquery-3.0.0.min.js
and jquery-3.0.0.js
files are exactly where they need to be, and _reference.js
has them listed as well, however BundleConfig.cs
can’t seem to find the correct file to include. The only way I can force it to include is by replacing {version}
with the actual version number. And with updates, this can turn untenable rather quickly.
Suggestions?
EDIT 1:
My BundleConfig.cs
, relevant section:
bundles.Add(new ScriptBundle("~/bundles/script.jquery").Include(
"~/Scripts/jquery-{version}.min.js"));
My _Layout.cshtml
:
@Scripts.Render("~/bundles/script.jquery")
And no, the dot in the name made no difference; I originally had it at the default, but had to change it to keep track of what I was adding.
Upvotes: 0
Views: 1361
Reputation: 726
Quoting a section from a Post by Rick Anderson:
Note: Unless EnableOptimizations is true or the debug attribute in the compilation Element in the Web.config file is set to false, files will not be bundled or minified. Additionally, the .min version of files will not be used, the full debug versions will be selected. EnableOptimizations overrides the debug attribute in the compilation Element in the Web.config file
I tested this and this works as long as you change the dot above to a dash in script.jquery to script-jquery (does not work with the dot separator).
Remember to enable optimizations for debug mode.
BundleTable.EnableOptimizations = true;
So the following should work:
BundleConfig.cs
:
bundles.Add(new ScriptBundle("~/bundles/script-jquery").Include(
"~/Scripts/jquery-{version}.min.js"));
//You will need the line below so already minified files can be picked up by the bundler in debug mode.
BundleTable.EnableOptimizations = true;
_Layout.cshtml
:
@Scripts.Render("~/bundles/script-jquery")
Upvotes: 2
Reputation: 3520
add
@Scripts.Render("~/bundles/script.jquery")
in head section of the layout.cshtml file. Also add
@RenderSection("scripts", required: false)
this is just a suggestion. I am not sure whether it will work or not.
Upvotes: 0