In previous versions of Razor I would conditionally load minified/debug versions of scripts by rendering a partial view that looked something like this:
@if (Context.IsDebuggingEnabled)
{
<script src="~/debug.js"></script>
}
else
{
<script src="~/release.js"></script>
}
If MVC6, vNext, VS2015, or whatever you call it :) I don't know how to accomplish this. Anyone know how?
Set a breakpoint on line 17. Run the app again. You can even debug the Razor Pages with markup and inspect the values of variables!
Select the ASP.NET Core project in Visual Studio Solution Explorer and click the Properties icon, or press Alt+Enter, or right-click and choose Properties. Select the Debug tab and click the link to open the Open debug launch profiles UI.
Enable runtime compilation at project creationIn the Create a new ASP.NET Core web application dialog: Select either the Web Application or the Web Application (Model-View-Controller) project template. Select the Enable Razor runtime compilation checkbox.
In MVC6, you can use the environment tag helper to load different versions of scripts depending for Development vs Production environments. This is based on the value of the value of the ASPNET_ENV environment variable.
<environment names="Development">
<script src="~/debug.js"></script>
</environment>
<environment names="Staging,Production">
<script src="~/release.js"></script>
</environment>
Bundling and minification would be handled using a task like Gulp or Grunt.
I have outlined the new approach in detail here: http://www.davepaquette.com/archive/2015/05/05/web-optimization-development-and-production-in-asp-net-mvc6.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With