asp.net MVC bundling with babel - asp.net

Is it possible to use babel in asp.net mvc without webpack?
With the use of standard bundling available in the starter project?

It is possible of course - msbuild is powerfull build system. In cases what I know it was done through gulp (call gulp tasks on compile).
But this is wrong way because you will need to spend your time on tooling when what you need is start developing as soon as possible. So stay with open terminal window, and run npm run my-compile manually.

Related

Update Css/Js bundles (Visual Studio Bundler Minifier) from the command line

I am in the process of creating automated update scripts for my websites. All websites are built using WebForms in Visual Studio 2017 (Not Core).
What I want to do is run a command line calling the bundlerconfig.json to update bundles for a certain project.
From what I can see there is a way using dotnet bundle, but I think this is just for DotNet Core projects.
Would be good to know either way whether this is possible or not. Thanks in advance.

Bundling and Minification in MVC 6

It looks like Bundling and Minification are no longer built into MVC 6 since there is no more App_Start and Bundle.Config.
Is this going to be the case after final release?
I'm guessing Grunt should be used since that seems to be baked into Visual Studio 2015.
UPDATE: It looks like Microsoft has switched to Gulp instead of Grunt in RC1.
Bundler & Minifier Extension
The default ASP.NET Core MVC 6 project template uses a Bundler & Minifier extension. The default template used to use Gulp which was far more powerful but it was deemed too complex for newbie developers who wanted something simple. You can read more about the switch away from Gulp and the reasoning here or read the documentation for the Bundler & Minifier extension here.
WebPack, Gulp, Grunt, Brocoli, etc.
A much nicer and far more powerful method is to use Gulp, or any other task runner (There are others named Grunt, Brocoli etc. Gulp is apparently nicer to work with and newer than Grunt but also more popular than Brocoli). You can use the ASP.NET MVC Boilerplate project template to get a project with Gulp built in.
The new kid on the block is called WebPack which is according to Google about as popular as Gulp at the moment.
ASP.NET MVC 5 Bundling and Minification and Smidge
The old bundling and minification in ASP.NET MVC 5 has been dropped but there is a project on GitHub to build it for MVC 6 called Smidge.
Grunt is the recommended approach in ASP.NET 5 applications. There are no plans to build a system like the previous ASP.NET Bundling and Minification (Optimization) system.
There is an extension for VS2015 to bundle and minify files, available here:
https://visualstudiogallery.msdn.microsoft.com/9ec27da7-e24b-4d56-8064-fd7e88ac1c40
I have just used this an also created an html helper to render unbundled/unminified files in debug mode, helper available here:
https://bundlerminifierhelper.codeplex.com/
Using these you don't need to have any knowledge of gulp, task runners etc.
SquishIt provides very similar capability and API to the MVC 5 bundling. Actually it predated MVC bundling. If you want to stay in the realm of .NET, ensure you can grow into more advanced bundling scenarios that will require tighter integration with contextual route attributes, avoid wasted time debugging serverside javascript that will fail silently when you make a minor typo or misplacement requiring you to eyeball all properties, and leverage the language that we know and love, then I'd recommend SquishIt.
Javascript has its place. In my opinion this is not its place.
By using squishit you'll also decouple one less thing from the whim of the ASP.NET team.
Alternatively, if you're looking for a very simple lightweight ASP.NET Core MVC6 Gulp template (instead of default .NET Core bundles), you can look at my github project.

How to use nuget package in ASP.NET vNext?

I am giving asp.net vNext a go and have created a new project. I wanted to pull in some dependencies and used NuGet as I usually would. I used it to pull in Require.js for example.
I now have a reference to this under ASP.NET 5.0 in the project references and I can see the path to where it is on my drive from the properties (myUserDrive/.kpm/packages/require... blah)
My question is, how do I use this? - historically it would have added the code to my web project.
For clientside libraries you should now use Bower. The latest previews of Visual Studio 2015 have built in support for NodeJS' NPM packages and Bower packages. It's a bit more complicated but together with Grunt you can do some pretty cool stuff.
Bower has a lot more libraries than NuGet and is more up to date.
For a good intro on all the new things in ASP.NET 5 I advise you to watch these videos on Channel 9: http://channel9.msdn.com/Series/Whats-New-with-ASPNET-5
The second video talks about NPM and Bower packages.
Bower: http://bower.io/ -> Search Packages
Visual Studio 2015 is allowing users to take advantage of popular open-source package management and build tools for processing client-side resources. They suggest using NuGet primarily for managing .NET packages.
The recommendations are:
Package Managers: NPM and Bower
NPM
Use Node Package Manager to install and manage build tools and plugins to compile source into client-side optimized files. NPM files are stored in "node_modules" (hidden in the VS project).
Configured using "packages.json".
Bower
Use the bower package manager to install and manage client libraries like "bootstrap", "jQuery", "angularjs". Bower files are stored in a folder named "bower_components" (hidden in VS project).
Configured using "bower.json".
Build Tools: GruntJS and GulpJS
Grunt
Grunt is a javascript task runner which allows you to setup build tasks to process your source into client-side ready resources. Use NPM to install grunt plugins that allow you to compose tasks (such as processing LESS or coffee files or minifying js and css).
Configured through "gruntfile.js".
Gulp
Gulp is a "streaming build system". Similar to grunt but allows more advanced streaming tasks to be defined. Use NPM to install gulp plugins that allow you to compose tasks (such as processing LESS or coffee files or minifying js and css).
Configured through "gulpfile.js".
Visual Studio 2015 provides some built-in support for these tools, including autocomplete for package names and version numbers. Visual Studio will check to make sure your packages are installed and up-to-date when you open the project. Finally there is the "Task Runner" UI which allows you to run grunt or gulp tasks manually or configure them to trigger on certain events.
This following post gives an introductory step by step guide to using these tools in Visual Studio 2015. Beyond that you should be able to search on NPM, Bower, Gruntjs or Gulpjs to find intro videos or blog posts to help you become more familiar with each.
http://www.asp.net/vnext/overview/aspnet-vnext/grunt-and-bower-in-visual-studio-2015

Should I use the aspnet_compiler with a website project?

We use Nant and devenv.com to build all our assemblies including the website project. Then we would use aspnet_compiler.exe to compile the published website.
Is this the correct way to do it? Historically, we always used the aspnet_compiler with plain vanilla website folders, but I'm not sure if this is really the correct tool for publishing websites that are part of a website project. It sort of feels wrong to have to do this as a 2 stage process using 2 different tools.
Using aspnet_compiler.exe is one of many ways to publish a website:
http://forums.asp.net/t/1544792.aspx#_What_is_the1
Since a web project can be compiled using msbuild (instead of devenv.com), you can also create a custom msbuild target to publish your files:
http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild
In this way, you can combine the compiling and publishing of the web site in one step.

Some doubts on setting an C#/Asp.Net 3.5 application automatic builder server

I want to set my server to automatically build my application upon commit on SVN repo, then deploy on a test/homologation server.
What I planning to do:
install a build tool (Nant? use MSBuild?);
create a simple script and set a hook to SVN that starts the process of building and deploy.
To do that, what I need to install on my server desides the .NET 3.5 framework? Is Nant capable of build our application based only on our solution file (.sln)?
I researched a little bit, and the Nant last release, v0.86 beta 1, does not include the solution target.
Is there other alternative to do that?
Note that currently I only use the VS2008 build system, and do not call the MSBuild directly. Is that feasible and simple to setup on server environment?
Just use CruiseControl.NET or TeamCity.
They're both fully-fledged continuous integration servers with lots of features and easy to configure.
We use Hudson to do that. Like mentioned before. It supports MsBuild (and Nant). We use msbuild with as paramters the solution file and the build configuration like debug/release (we created a deploy and watin configuration with different web.config's). No extra tasks or different scripts than the solution file we us in visual studio. (which I think is the setup you're after)
Additionally before deployment we setup a webserver (cassini) with the results of the build execute nunit (watin) tests. All through Hudson, which shows a nice diagram of the nunit test results.
TeamCity and CruiseControl.Net should be capable of doing the same thing,but I found hudson to be a snap to setup, and configure. (It has everything included in a package just start it)
What's also nice is that it supports SourceCop and FxCop results which you can view in a diagram and look at the location a certain warning applies to in the sourcefile, all using the web interface.
You could use Hudson or Cruise Control for it.
They are Continuous Integration Servers, and can also run your unit tests before deploying it.
I think you are looking at installing Cruise Control.Net. It will handle automatically checking your SCM repository, and kicking off anything build related you want.
http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET
As for NAnt or MSBuild - it's a personal choice. I went with MSBuild as NAnt hasn't been updated in a while. That being said - they are both capable of doing whatever it is you are looking to do.
One note - if you compile in Visual Studio - you are using MSBuild. You can target the SLN or PROJ files with MSBuild through Cruise Control.net.
I use Teamcity and it was very easy to set up. Before that I used plain Nant. The Teamcity server realy changed things, because now everybody in the team understands what is going on on the buildserver.
It is free for up to 20 project configurations.
For Asp.Net you will also need Web Deployment Project on any type of buildserver you choose.
Are you realy shure you need to build sln? For a typical ASP.NET project this is not the best way. You usually build a WebDeploymentProject. Anyway Teamcity (and other buildservers I guess too) understands sln-files.

Resources