Update on April, 30 2015
When I wrote this blog post, I wrote that Microsoft was not planning to support VB.NET in ASP.NET 5/MVC 6. That was true when I wrote the blog post, but this blog post generated some strong reactions from the VB.NET community. Well, it looks like VB.NET is back!
I spent the last couple of weeks writing sample code for ASP.NET 5/MVC 6 and I was surprised by the depth of the changes in the current beta release of ASP.NET 5. ASP.NET 5 is the most significant new release of ASP.NET in the history of the ASP.NET framework — it has been rewritten from the ground up.
In this blog post, I list what I consider to be the top 10 most significant changes in ASP.NET 5. This is a highly opinionated list. If other changes strike you as more significant, please describe the change in a comment.
1. ASP.NET on OSX and Linux
For the first time in the history of ASP.NET, you can run ASP.NET 5 applications on OSX and Linux. Let me repeat this. ASP.NET 5 apps can run on Windows, OSX, and Linux. This fact opens up ASP.NET to a whole new audience of developers and designers.
The traditional audience for ASP.NET is professional developers working in a corporation. Corporate customers are welded to their Windows machines.
Startups, in stark contrast, tend to use OSX/Linux. Whenever I attend a startup conference, the only machines that I see in the audience are Macbook Pros. These people are not the traditional users of ASP.NET.
Furthermore, designers and front-end developers – at least when they are outside the corporate prison – also tend to use Macbook Pros. Whenever I attend a jQuery conference, I see Macbook Pros everywhere (the following picture is from the jQuery blog).
Enabling ASP.NET 5 to run on Windows, OSX, and Linux changes everything. For the first time, all developers and designers can start building apps with ASP.NET 5. And, they can use their favorite development environments such as Sublime Text and WebStorm when working with ASP.NET apps (No Visual Studio required).
Take a look at the OmniSharp project to see how you can use editors such as Sublime Text, Atom, Emacs, and Brackets with ASP.NET 5:
2. No More Web Forms
I love ASP.NET Web Forms. I’ve spent hundreds – if not thousands – of hours of my life building Web Forms applications. However, it is finally time to say goodbye. ASP.NET Web Forms is not part of ASP.NET 5.
You can continue to build Web Forms apps in Visual Studio 2015 by targeting the .NET 4.6 framework. However, Web Forms apps cannot take advantage of any of the cool new features of ASP.NET 5 described in this list. If you don’t want to be left behind as history marches forward then it is finally time for you to rewrite your Web Forms app into ASP.NET MVC.
3. No More Visual Basic
It is also time to say goodbye to Visual Basic. ASP.NET 5 only supports C# and Visual Basic is left behind.
My hope is that this change won’t be too painful. I believe that there are only two people in the entire world who are building MVC apps in Visual Basic. It is time for both of you to stop it. There are good automatic converters for going from Visual Basic to C#:
4. Tag Helpers
Tag Helpers is the one feature that might have the biggest impact on the way that you create your views in an ASP.NET MVC application. Tag Helpers are a better alternative to using traditional MVC helpers.
Consider the following MVC view that contains a form for creating a new product:
@model MyProject.Models.Product @using (Html.BeginForm()) { <div> @Html.LabelFor(m => p.Name, "Name:") @Html.TextBoxFor(m => p.Name) </div> <input type="submit" value="Create" /> }
In the view above, the Html.BeginForm(), Html.LabelFor(), and Html.TextBoxFor() helpers are used to create the form. These helpers would not be familiar to an HTML designer.
Here’s how the exact same form can be created by using Tag Helpers:
@model MyProject.Models.Product @addtaghelper "Microsoft.AspNet.Mvc.TagHelpers" <form asp-controller="Products" asp-action="Create" method="post"> <div> <label asp-for="Name">Name:</label> <input asp-for="Name" /> </div> <input type="submit" value="Save" /> </form>
Notice that this new version of the form contains only (what looks like) HTML elements. For example, the form contains an INPUT element instead of an Html.TextBoxFor() helper. A front-end designer would be fine with this page.
The only thing special about this view is the special asp-for attributes. These attributes are used to extend the elements with server-side ASP.NET MVC functionality.
Damien Edwards put together an entire sample site that uses nothing but Tag Helpers here:
https://github.com/DamianEdwards/TagHelperStarterWeb
5. View Components
Goodbye subcontrollers and hello View Components!
In previous versions of ASP.NET MVC, you used the Html.Action() helper to invoke a subcontroller. For example, imagine that you want to display banner ads in multiple views. In that case, you would create a subcontroller that contained the logic for returning a particular banner advertisement and call the subcontroller by invoking Html.Action() from a view.
Subcontrollers – the Html.Action() helper — are not included in the current beta of MVC 6. Instead, MVC 6 includes an alternative technology called View Components.
Here’s how you can create a View Component that displays one of two banner advertisements depending on the time of day:
using Microsoft.AspNet.Mvc; using System; namespace Partials.Components { public class BannerAd : ViewComponent { public IViewComponentResult Invoke() { var adText = "Buy more coffee!"; if (DateTime.Now.Hour > 18) { adText = "Buy more warm milk!"; } return View("_Advertisement", adText); } } }
If the time is before 5:00pm then the View Component returns a partial named _Advertisement with the advertisement text “Buy more coffee!”. If the time is after 5:00pm then the text changes to “Buy more warm milk!”.
Here’s what the _Advertisement partial looks like:
@model string <div style="border:2px solid green;padding:15px"> @Model </div>
Finally, here is how you can use the BannerAd View Component in an MVC view:
@Component.Invoke("BannerAd")
View Components are very similar to subcontrollers. However, subcontrollers were always a little odd. They were pretending to be controller actions but they were not really controller actions. View Components just seem more natural.
6. GruntJS, NPM, and Bower Support
Front-end development gets a lot of love in ASP.NET 5 through its support for GruntJS (and eventually Gulp).
GruntJS is a task runner that enables you to build front-end resources such as JavaScript and CSS files. For example, you can use GruntJS to concatenate and minify your JavaScript files whenever you perform a build in Visual Studio.
There are thousands of GruntJS plugins that enable you to do an amazing variety of different tasks (there are currently 4,334 plugins listed in the GruntJS plugin repository):
For example, there are plugins for running JavaScript unit tests, for validating the code quality of your JavaScript (jshint), compiling LESS and Sass files into CSS, compiling TypeScript into JavaScript, and minifying images.
In order to support GruntJS, Microsoft needed to support two new package managers (beyond NuGet). First, because GruntJS plugins are distributed as NPM packages, Microsoft added support for NPM packages.
Second, because many client-side resources – such as Twitter Bootstrap, jQuery, Polymer, and AngularJS – are distributed through Bower, Microsoft added support for Bower.
This means that you can run GruntJS using plugins from NPM and client resources from Bower.
7. Unified MVC and Web API Controllers
In previous versions of ASP.NET MVC, MVC controllers were different than Web API controllers. An MVC controller used the System.Web.MVC.Controller base class and a Web API controller used the System.Web.Http.ApiController base class.
In MVC 6, there is one and only one Controller class that is the base class for both MVC and Web API controllers. There is only the Microsoft.AspNet.Mvc.Controller class.
MVC 6 controllers return an IActionResult. When used as an MVC controller, the IActionResult might be a view. When used as a Web API controller, the IActionResult might be data (such as a list of products). The same controller might have actions that return both views and data.
In MVC 6, both MVC controllers and Web API controllers use the same routes. You can use either convention-based routes or attribute routes and they apply to all controllers in a project.
8. AngularJS
AngularJS is one of the most popular client-side frameworks for building Single Page Applications (SPAs). Visual Studio 2015 includes templates for creating AngularJS modules, controllers, directives, and factories.
The support in ASP.NET 5 for GruntJS makes ASP.NET an excellent server-side framework for building client-side AngularJS apps. You can combine and minify all of your AngularJS files automatically whenever you perform a build. You can interact with an MVC 6 controller from an AngularJS $resource using REST.
9. ASP.NET Dependency Injection Framework
ASP.NET 5 has built-in support for Dependency Injection and the Service Locator pattern. This means that you no longer need to rely on third-party Dependency Injection frameworks such as Ninject or AutoFac.
Imagine, for example, that you have created an IRepository interface and an EFRepository class that implements that interface. In that case, you can bind the EFRepository class to the IRepository interface in the ConfigureServices() method of the Startup.cs class like this:
services.AddTransient<IRepository, EFRepository>();
After you bind EFRepository and IRepository then you can use constructor dependency injection in your MVC controllers (and any other class) using code like this:
public class ProductsController : Controller { private IRepository _repo; public ProductsController(IRepository repo) { _repo = repo; } }
In the code above, the IRepository interface is passed to the constructor for the ProductsController. The built-in ASP.NET Dependency Injection framework passes EFRepository to the ProductsController because IRepository was bound to EFRepository.
You also can use the Service Locator pattern. Wherever you can access the HttpContext, you can access any registered services. For example, you can retrieve the EFRepository by using the following code inside of an MVC controller action:
var repo = this.Context.ApplicationServices.GetRequiredService<IRepository>();
10. xUnit.net
Goodbye Visual Studio Unit Testing Framework and hello xUnit.net!
In previous versions of ASP.NET MVC, the default testing framework was the Visual Studio Unit Testing Framework (sometimes called mstest). This framework uses the [TestClass] and [TestMethod] attributes to describe a unit test:
[TestClass] public class CalculatorTests { [TestMethod] public void TestAddNumbers() { // Arrange var calc = new Calculator(); // Act var result = calc.AddNumbers(0, 0); // Assert Assert.AreEqual(0, result); } }
ASP.NET 5 uses xUnit.net as its unit test framework. This framework uses the [Fact] attribute instead of the [TestMethod] attribute (and no [TestClass] attribute]):
public class CalculatorTests { [Fact] public void AddNumbers() { // Arrange var calculator = new Calculator(); // Act var result = calculator.AddNumbers(1, 1); // Assert Assert.Equal(result, 13); } }
If you look at the source code for ASP.NET 5 then you’ll see that xUnit.net is used to test ASP.NET extensively. For example, the MVC repository contains unit tests written with xUnit.net. You can take a look at the MVC repository (and its unit tests) here:
ASP.NET uses a fork of xUnit.net that is located here:
Please, revise the VB affirmation… If you aren’t strictly correct can cause FUD
I’m getting my information from the official aspnet repository: “ASP.NET 5 is C# only at this point and that will not change before we RTM. We plan to have extensibility points so other languages like VB, F#, etc can be added via the form of a support package or such.” See https://github.com/aspnet/Home/issues/236
“No More Visual Basic”… Wait! What? Is this official and no support planned in the future? I always assumed VB was coming later and C#-only was just how the CTP was.
@Stilgar – according to this issue from the aspnet repository “ASP.NET 5 is C# only at this point and that will not change before we RTM”. See https://github.com/aspnet/Home/issues/236
My understanding is that this answer says VB.NET support is coming in some form.
@Stilgar — Take a look at this SO answer “There are no plans to support VB in ASP.NET 5 in terms of compilation, project templates, and other tools…ASP.NET 5 has some in-progress support to enable non-C# compilers to be used, but there is still no official plans to support VB (you’d have to roll your own).”
See http://stackoverflow.com/questions/28040944/vb-net-support-for-asp-net-5-mvc6
Stephen is correct. VB is not part of ASP.NET future. End of story. OTOH, it will be around for a long time regardless.
If you read the GitHub question linked in that SO discussion, you’d see that it’s C# until RTM. That’s all. There has been no definitive statement about Microsoft shoving VB.NET out to pasture, and the part in this blog post was significantly misinforming I was also more than a little unprofessional and snide.
VB.NET’s usage rate is still considerably high, and many enterprise customers of Microsoft have significant investments in VB.NET. The numbers can be seen in Forester studies, as well as various articles and surveys in places like InfoWorld. I really don’t see not being able to create an ASP.NET 5 project in VB.NET after RTM.
While it may be interesting to some on a meta level that fanboy flaming applies not only to Android vs. IOS, Mac vs. Windows, and Java vs. .NET, but that some even extend it to different .NET languages, despite being in the same development environment, frameworks, with nearly identical il code, etc… That said, those types of debates usually still end up very much a waste of time.
I’d wait until some definitive information from Microsoft, rather than a derogative aside misinterpreting a SO post referencing another post, etc…
Could have sworn that was originally
“… and it was also more than a little unprofessional and snide.”
rather than:
“… I was also more than a little unprofessional and snide.”
Oops, completely different meaning. 😉
I think some of the things are taken a bit out of context.
Like 10. xUnit.net. Yes it is true that the ASP.NET team are using xUnit, but as stated here “https://github.com/aspnet/Home/issues/214” they plan on supporting MSTest.
Also they are adding new features to web forms like they say: http://www.asp.net/vnext/overview/aspnet-vnext/aspnet-5-overview#webforms
But we can totally agree that people should move on.
Interesting statement on Web Forms support – that seems to conflict with the statement on the ASP.NET 5 web site, which reads: “You can continue developing Web Forms apps and have confidence that Web Forms is an essential part of the .NET web development platform. We remain focused on adding new features to Web Forms to improve the development experience and keep the technology up-to-date with web practices.”
Sounds like a bit of creative salesmanship to me. While they are adding features to WebForms, there is NO support for .Net 5.0 (and likely will never have it), so it’s more or less on the track to retirement. Imagine if a product that only works on .Net 2.0 kept getting features: I’d call it a dead/dying product even if people are still using it since the product can’t take advantage of new _language_ features.
Yes, Web Forms and VB are dead end technologies in the Microsoft world. It’s not like you couldn’t see it coming. OTOH, no one is making you upgrade.
I find it hard to believe they are going to drop support for webforms. One Application I support has 100s of webforms. We have two developers. It would takes two full years of work to convert it to MVC.
@Todd — There is no evidence that Microsoft is planning to drop product support for Web Forms or VB.NET. In fact, Microsoft is continuing to invest in Web Forms by adding new features. As I mention in the blog post above, you can continue to build Web Forms apps using Visual Studio 2015.
However, that being said, Web Forms and VB.NET are not part of ASP.NET 5. So you cannot take advantage of many of the new ASP.NET 5 features described in the blog post — such as OSX/Linux support or GruntJS support — in a Web Forms or VB.NET app.
The bottom line is that if I was forced to decide on the ASP.NET technology to use for building a new Web application today then I would use C#/MVC with ASP.NET 5.
See https://github.com/aspnet/Home/issues/349
Rob Conery said http://codebetter.com/robconery/2009/04/23/i-spose-i-ll-just-say-it-you-should-learn-mvc/; Jim Newkirk created xUnit.net with Brad Wilson; kzu switched to xUnit.net for moq … c# now leaving VB in the dust … it’s about time … nevertheless, i’m flabbergasted … please excuse me while i go and check a printed calendar … i need to assure myself that today is not April 1st
I expect that there will be a publicly available package before it goes gold “We plan to have extensibility points so other languages like VB, F#, etc can be added via the form of a support package or such.” there are just too many developed apps to leave it swinging going forward. As far a requirement to use MVC, I am sure that will change as well.
You are in denial. Web forms and VB are being left out of the new lean and mean .NET 5.0. It’s a subset and will never have those features. Sorry if that ruins your day but this was their intention and they have been saying this for over 2 years.
But Microsoft has obviously not been explaining it very clearly otherwise Stephen wouldn’t have needed to reference a github issue https://github.com/aspnet/Home/issues/236. It would have been laid out loud and clear by Microsoft by someone like Scott Guthrie or Scott Hanselman in a clear fashion.
Thank God, no more VB crap!
I have written exactly zero lines of VB.NET but it always seemed like a fine language to me. I don’t see why anyone would consider it “crap”
The fact that you haven’t written a line of it, AT ALL, to me, speaks volumes of why people consider it “crap”. Maybe not “crap” but not worthy of dual support. I’ve seen resumes that say “No VB under any circumstances”.
If you had a brand new project, VB would not likely be first choice for language for a jillion reasons.
If the world labeled every language I have not used “crap” or not worthy of support there would be very few languages indeed. Whole industries would be in trouble because I never used the languages they were built upon 🙂
> For the first time in the history of ASP.NET, you can run ASP.NET 5 applications on OSX and Linux.
Nope, ASP.NET MVC app have been supported on Mono for a long time. I’m running two right now (and have for 2 or 3 years).
> GruntJS, NPM, and Bower Support
This is a Visual Studio feature, not an ASP.NET feature. Also Gulp is better than Grunt, and both are supported.
> No More Web Forms
Web forms are still supported. From the ASP.NET site:
> You can continue developing Web Forms apps and have confidence that Web Forms is an essential part of the .NET web development platform. We remain focused on adding new features to Web Forms to improve the development experience and keep the technology up-to-date with web practices.
@Daniel — good point about Mono. I should have written “For the first time, the very same ASP.NET framework that runs on Windows will run on OSX/Linux”. Mono, unlike the new ASP.NET 5, is a separate code base.
And, I am not saying that Web Forms won’t be supported — I’m just pointing out that Web Forms won’t be part of ASP.NET 5. So, for example, you won’t be able to run Web Forms on OSX/Linux using ASP.NET 5.
I’d like to see some type safety in tag helpers, because “form asp-controller=’Products’ asp-action=’Create’ … ” looks too brittle for refactoring and compiler checking
Is there any plans to support that?
Otherwise the only way I can think of is code generation with a global list of strings for controller names, plus the same list of actions for each.
Unless you’ve been precompiling your views they’ve never been particularly friendly towards refactoring or type checking. Just yesterday I refactored a property name on my model and forgot to update the view and it blew up at run-time.
No VB and no Web Forms are the right decision.
I hope MS stands their ground and doesn’t change their direction. As a former VB.NET developer I can truthfully say that learning C# was the right decision for me. I love the direction that Microsoft is going with ASP.NET, Visual Studio, Azure, C#, etc. etc.
This is a great time to be a developer.
I hope MS has plans for items that don’t work in MVC like report viewer control, etc. I love Mac and Linux integration, but am surprised about VB.
“Tag Helpers are a better alternative to using traditional MVC helpers.” – I disagree: https://github.com/aspnet/Razor/issues/88#issuecomment-68180864
@glen – I notice that they recently added a feature to add prefixes to tags used by Tag Helpers. See https://github.com/aspnet/Razor/issues/309 — it appears that this feature is optional which should make everyone happy 🙂
Hi stelhen.
Could you please give me more resources to read about this:
“You can interact with an MVC 6 controller from an AngularJS $resource using REST” ..
@mohammad – take a look a the following blog post http://stephenwalther.com/archive/2015/01/13/asp-net-5-and-angularjs-part-2-using-the-mvc-6-web-api
How do we use Tag Helpers in place of EditorFor? These don’t seem like replacements for that.
‘you can run ASP.NET 5 applications on OSX’
Presumably you mean so long as a dev ide is installed, or a client web server, unless you are talking about Cordova apps? Thank you in advance for any clarification.
@rod — ASP.NET Core 5.0 is truly cross-platform: you can run ASP.NET on OSX/Linux in the same way as you can on Windows. ASP.NET includes a web server named Kestrel that you can run from the command line and use to serve ASP.NET 5 Web applications. This is not dependent on Visual Studio. You can build ASP.NET apps using Sublime Text or (for that matter) TextEdit.
…well that is really good news indeed – kestrel it is, thank you. Hopefully kestrel might just run on demand so the user doesn’t have to start it up.
I’ve suggested a couple of things on Scott G’s site. I know open source is all the buzz for a lot of non-Windows devs but, having come back to .NET after several years (I’m a production man first, coder second) my head really spins over all this angular/grunt/bower stuff (the list goes on). I just wish it was all VS vNext. How about Anders writing a nice C# compiler that outputs all these JavaScript implementations so I don’t have to reach for the aspirins in the cupboard?
And finally a whacky idea. Back in 2000 when .NET was about to be launched, we marvelled at the simplicity of web + Windows (UI) apps and the prospect of common business and data layers. I hoped for the day when there was a single control set to go even further. What about rendering HTML and all this ASP.NET stuff for non-Windows devices whilst streaming XAML Universal Apps elsewhere i.e. finally one set of controls?
Thanks for listening. R
The majority of start-up developers using OSX/Linux are unlikely to use ASP.NET. Why? Clearly they opted not to purchase a Microsoft Surface or 3rd party machine running Windows OS. So, it is somewhat reasonable to say they are likely to use non-Microsoft web development technology as well e.g. PHP etc.
MVC has been around for decades. Why Microsoft did not go with ASP.NET MVC circa 2002 immediately was in hind sight a poor choice. Instead, they went with ASP.NET Web Forms and now millions of developers know it very well. However, these days ASP.NET MVC is getting all the love. Subsequently, many ASP.NET Web Forms developers have abandoned Microsoft in favour of other technologies that stay the course.
You say “it is finally time for you to rewrite your Web Forms app into ASP.NET MVC”.
So for the thousands of people, businesses and corporates that have spent a decade developing web forms apps, do you really mean throw it away and start from scratch?
Who can justify the time? Who pays for it? What real value does it provide? None. Sure for new projects MVC should be considered (except for say intranets). Sorry and no offence, but “rewrite your apps” is not the best advice.
GruntJS, NPM, and Bower. My prediction is they will disappear by 2020 in favour of something new. Cool kids get bored and move on to something different when the crowd copies them.
Microsoft should chart its own roadmap and stick to it. It is what true leaders do. Trying to be all things to all people is hard and usually fails.
I agree with a lot of your points. For the company I work for “rewrite your apps” is not on option for us anytime soon if at all. We have far too many web forms sites and a whole in-house framework built using web forms. We are starting to add MVC but there’s no easy quick way for us to switch our Web Forms to MVC.
We’ve been burned by Microsoft many times. I like a lot of what they’re doing now but man there are times that they really make things difficult. Naturally we are using VB.NET so if that’s not supported that’s a big deal. Not from a learning c# standpoint but just from a consistency perspective. One assembly in VB.NET and one in C#. Not that big a deal but not ideal.
100% agree! Microsoft completely lacks a consistent roadmap for web/server development. Web development is shifting from backend rendering to frontend rendering (JavaScript…). We are still in time of transition. But frontend rendering will get much more complex, more logic will go to front end etc. As a result, abstraction is crucial. They need some way to build a typed GUI that is decoupled from JavaScript logic.
In my opinion the biggest failure was to hear the designer guys that want control over HTML formatting like Razor View. HTML is just fucking markup. No one cares if it looks ugly or whatever as long as you follow the specifications. Razor is the most ugliest and worst piece of view that was ever developed by Microsoft. Even old school MFC C++ is much more logical and easier to understand. Because there is ABSTRACTION to solve problems. You always need abstraction to solve complex problems.
Microsoft needs to do:
– build JavaScript APIs for frontend development
– build a XAML parser that generates the markup and interacts with the JavaScript libraries
– commit to ONE communication API. I still don’t see why we need WebApi in the backend. WCF is much more powerful and easier to configure.
Stephen, congrats, you’ve found those two developers that use VB for ASP.NET! 😀 Great and witty post.
Vytautas you’re jumping to conclusions. (But I do see the humour in your comment)
I write code in C#.
anyone would like to discuss why we should start using x-unit for unit testing instead of MS test? people should discuss the advantages of x-unit for which we should use it and also should discuss the down side of ms-test. looking for information. thanks
No more VB and Web Forms? Hallelujah! Time to move on and expand your horizons 90’s developer guy.
Dear Stephen,
Being ASP.NET WebForms Developer (both C# and VB), Finally It’s time to completely learn MVC. 🙂
It’s time to upgrade skills (Classic ASP 3.0 -> ASP.NET WebForms -> ASP.NET MVC)
Please publish books for ASP.NET 5 and MVC 6 ASAP..!