I'm trying to add a bundle for Knockout in my application. From NuGet, I got two scripts:
knockout-3.0.0.debug.js and
knockout-3.0.0.js
I'm using the following code.
bundles.Add(new ScriptBundle("~/bundles/knockout").Include(
"~/Scripts/knockout-{version}.js"));
For some reason, it will include the "debug" version:
<script src="/Scripts/knockout-3.0.0.debug.js"></script>
My question:
How can I get the non-debug version?
(I have tried running in both debug and release configurations, with the same result)
Best regards,
Thomas
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
more info
Related
I had a previously working local configuration that is not bundling even with forcing the settings.
This is happening on both JS and CSS bundling.
Example code only
private static List<string> ScriptBundleExample
{
get
{
return new List<string>()
{
"~/Assets/javascriptfile1.js",
"~/Assets/javascriptfile2.js",
};
}
}
// separate function
var bundle = new ScriptBundle("~/Bundles/javascript-example");
ScriptBundleExample.ForEach(script => {
bundle.Include(script)
}
bundles.Add(bundle);
I have appropriately added the render in my layout:
// different casing to above but never mattered
#Scripts.Render("~/bundles/javascript-example")
I have forced the setting here which should be bundling correctly:
Note: This setting overrides the debug setting within Web.config yet it still doesn't work with both overrides.
BundleTable.EnableOptimizations = true;
I have also turned off any debugging in Web.config (both in wwwroot and the project file):
<compilation debug="false" targetFramework="4.7.2" />
FWIW minifying also isn't working:
bundle.Transforms.Add(new JsMinify());
Previous related questions on SO
MVC Bundling Not Working
The OP worked on the assumption debug="true" was the correct setting which it was not.
Bundled scripts not working MVC
This was a minification issue which is not the case here.
MVC Bundle not working with Release Configuration (Debug is False), CSS and JS not loading
I'm not getting 404 errors because the bundling isn't working but the proper files are still coming out the server as individual scripts (as if I'm always in debug mode) so the files are being included correctly.
ASP.NET MVC Bundle not rendering script files on staging server. It works on development server
This person just didn't understand the bundling and minification process.
WebGrease package exists in my solution.
Why is my CSS bundling not working with a bin deployed MVC4 app?
Same as above, the OP did not understand how these settings worked. I do not have a .js extension in my bundles.
https://stack247.wordpress.com/2013/02/08/mvc-bundle-not-working-with-release-configuration-debug-is-false/
Not in SO but this didn't work.
Everything I did above was correct from a C# point of view. Through running some breakpoints, I realised that the code was bundling correctly but was being overridden by another setting in the pipeline after the one above executed which set BundleTable.EnableOptimizations to false and unbundled everything.
So for anyone reading ahead, if you set the same settings as above, you've done everything right to bundle it from a C# perspective. Check through debugging that the setting is not being overwritten elsewhere.
I have a web site I just took over and am wanting to get web transformations working. I have always had success with MVC projects doing this for debug and release but this ASP web pages application refuses to cooperate.
I apologize if this is a duplicate. I see a lot of questions like this but nothing has solved my issue yet.
If I press F5 and run, I get web.config settings as I expect.
If I publish my "Test" profile (debug mode) I get web.Test.Config transformations as expected.
If I publish my "Release" profile I get the same web.Test.Config transformations and NOT the release one.
Possible issues or things that may be of interest:
The web.config file expands in the solution to show the debug file. The release file is not part of this and is listed separately below.
I tried changing the compilation setting for debug to false in the main web.config. This had no effect.
In the SLN file I noticed that I have lines in the GlobalSection for postSolution that list my project GUID followed by .Debug or .Release. BOTH of these say "Debug|Any CPU" at the end. I changed the release ones to say "Release|Any CPU". I republished but VS just changed this back to Debug on me.
In Build -> Configuration Manager, I select Release as thje Active soltion configuration. In the Project contexts box, my application only has Debug available in the Configuration column drop down.
Edit: I noticed that in website.publishproj there was no section for Release. There was a PropertyGroup with configuration of Debug but that's all. Being cavalier or stupid I ignored the "do not modify this file" message and added the release section. This had no effect.
Edit: Photo pasted in. The dropdown is expanded.
The highlighted dropdown is where you would need to add the configuration back in:
I am developing an app in Xamarin Android and I keep getting this warning in Visual Studio:
Android Application is running (debug is disabled in android project
properties)
View Image
How can i enable debug in android project properties?? I have added in AssemblyInfo.cs the following code as mentioned somewhere.
#if DEBUG
[assembly: Application(Debuggable = true)]
#else
[assembly: Application(Debuggable=false)]
#endif
But nothing changes and no breakpoints are being hit.
There are a few things you need to look at.
1) One way to double check that it is at the project level would be looking at the csproj file for the project using notepad++ or some other text editor and looking at the debugtype, debugger, debug symbols for the property group Debug|X
2) Make sure the setting inside the project properties that enable developer instrumentation is checked.. may be a little different in Xamarin Studio or an iOS project
3) If those simple properties are all set properly you may have a bigger issue related to mbd files not getting properly updated. Some people have had success clearing their debug folder and obj folders within the project so that the mbd files get rebuilt.
https://forums.xamarin.com/discussion/40832/breakpoints-not-being-hit-for-android-and-xamarin-forms
In my case, finally restart of Visual Studio helped (maybe due to a VS/Xamarin bug). (Project was configured properly.)
i had the same problem. Then I :
Clean the project. Also delete obj and res folder, in your
project directory, to be sure.
Run it in debug mode instead of release mode - refer to image below. after changing to debug mode press F5.
I had to turn Optimize Code option OFF which I had turned ON by mistake I think.
After that delete bin and obj folders and rebuilding did the work.
In my case -> build -> Configuration Manager -> change de relea
Problem:
In the HTML5 offline app being done in ASP.NET MVC 4.5, we are bundling and minifying the styles and scripts using the framework's built-in feature. Everything working well with the pages themselves, but for writing into the Cache Manifest, where (because of the we we are writing it) it is always only emitting the bundled URL.
And so, we are not able to debug JavaScript in the offline mode, as the individual debug js files are not getting into the application cache.
Code:
RegisterBundles
This is how our BundleConfig.RegisterBundles look:
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/Scripts").Include(
"~/Scripts/*.js"
));
}
HTML Markup
And we include it in our _Layout.cshtml for the pages itself like this:
#System.Web.Optimization.Scripts.Render("~/bundles/Scripts")
This works well for the pages, by emitting the individual js files when debug is true, and one bundled file when debug is false.
Output in debug=true
<script src="/Scripts/ScriptOne.js"></script>
<script src="/Scripts/ScriptTwo.js"></script>
<script src="/Scripts/ScriptThree.js"></script>
Output in debug=false
<script src="/bundles/Scripts?v=B0_RvAM_5ifnREcGnNQ3FO8qQp4vyLOdtCUJ-2mXSuA1"></script>
Cache-Manifest
And this is how we include the scripts into our CacheManifest
#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/Scripts")
Output in debug=true and debug=false
/bundles/Scripts?v=B0_RvAM_5ifnREcGnNQ3FO8qQp4vyLOdtCUJ-2mXSuA1
What we want?
We would like to know if there is a way we could get the Cache-Manifest to be output like this:
Output in debug=true
/Scripts/ScriptOne.js
/Scripts/ScriptTwo.js
/Scripts/ScriptThree.js
Output in debug=false
/bundles/Scripts?v=B0_RvAM_5ifnREcGnNQ3FO8qQp4vyLOdtCUJ-2mXSuA1
The MSDN documentation talks about a certain Scripts.RenderFormat method, which looked like a good candidate for doing what we want. But intellisense was complaining this RenderFormat method is not present in the version of System.Web.Optimization currently referenced.
But, thanks (once again) to Google, this answer here on SO was explaining that this RenderFormat method is in fact, included in the next version's alpha release. And the comment on that answer linked to the page that explains how we could install it:
PM> Install-Package Microsoft.AspNet.Web.Optimization -Pre
With this version, the Cache-Manifest could be changed to:
#System.Web.Optimization.Scripts.RenderFormat("{0}","~/bundles/Scripts")
And we now have the cache manifest emit the individual files while debug=true.
Apparently, the MSDN documentation is not in sync with the current stable release !
When building a C# application with Visual Studio 2008, is it possible to set a different output filename per configuration?
e.g.
MyApp_Debug.exe
MyApp_Release.exe
I tried a post-build step to rename the file by appending the current configuration, but that seems a scrappy approach. Plus it meant that Visual Studio could no longer find the file when pressing F5 to start debugging.
You can achieve this by editing your project file by hand. Locate the <AssemblyName> node and add a conditional attribute to it:
<AssemblyName Condition="'$(Configuration)'=='Debug'">MyApp_Debug.exe</AssemblyName>
<AssemblyName Condition="'$(Configuration)'=='Release'">MyApp_Release.exe</AssemblyName>
You'll have to duplicate it also to add another conditional attribute for the release version.
Whilst it is possible, it may cause problems. There is an AssemblyConfiguration attribute that can be applied to your assembly. In AssemblyInfo.cs, put:
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif
This will add a property to your compiled assembly that will tell you which build configuration your application was built using.
As adrianbanks mentioned, you can edit your .csproj file by hand to accomplish this.
I would, however reccomend the simpler form of:
<AssemblyName>MyApp_$(Configuration).exe</AssemblyName>
If you ever edit the properties of this project however, this change will very likely be lost. It's something you will have to manually stay on top of, as it's not going to be a supported setup.
To manually edit your project definition, right click the project in Visual Studio, and select "Unload", then right click the unloaded project, and select "Edit" and it will open the XML definition for you.
I'm sure there is, however in my experience having different filenames for debug / release configurations is a bad idea as it can cause all sorts of problems (very much like the issue VS has when it tries to execute the renamed app)
Why not simply indicate whether or not its debug / release in the Assembly attributes (for example in the comments)