Scott Hanselman

Introducing Gulp, Grunt, Bower, and npm support for Visual Studio

September 02, 2014 Comment on this post [75] Posted in ASP.NET | Tools | VS2013
Sponsored By

Web Development, specifically front end web development, is fast becoming as complex and sophisticated as traditional back end development. Most projects don't just upload some JS and CSS files via FTP. There's now a front end build process that can include expansion of SASS and LESS, minification of CSS/JS, running JSHint or JSLint, and much more. These build tasks and processes are coordinated with tools like Gulp and Grunt. Additionally, client-side libraries are managed as packages using management systems like npm and bower.

Why client-side package managers for ASP.NET? Why not NuGet? Why not MSBuild?

Some of you may ask, why not use NuGet for JavaScript? Why not extend MSBuild for building CSS/JS? Simple. Because there's already a rich ecosystem for this kind of thing. NuGet is great for server side libraries (and some client-side) but there are so many more CSS and JS libs on npm and bower. MSBuild is great for server-side builds but can be overkill when building a client-side app.

So, use both. These are tools in your toolkit. Adding support for Gulp, Grunt, Bower, npm (and other stuff, in the future if needed) means a more familiar environment for front-end devs doing ASP.NET and it opens the doors for ASP.NET devs to bring in the JS and CSS libraries communities use every day.

Introducing Task Runner Explorer

We’ve received a ton of feature requests regarding Grunt/Gulp support from many of you as well as the community at large. We are building first-class support for both Grunt and Gulp in Visual Studio “14” with full extensibility. Now we’re ready to ship a preview of this support as an extension to VS2013 and would appreciate your help testing and exploring this feature. 

Today we're introducing a preview of the "Task Runner Explorer" as a VSIX extension. We're also recommending two other VSIXs to round out the experience for this feature.

NOTE: Much of the functionality included in these multiple VSIX extensions will be built into Visual Studio so you won't need to install so many things. However, for VS2013 and this preview we needed multiple VSIXs in order to get you the bits sooner than later. Also note that today only Task Runner Explorer will work on Visual Studio Express but for VS14 all  the features will work in the free VS Express version.

Consider these features as a "DevLabs" preview for now, much like the VS Productivity Power Tools. They'll graduate into the final product.

What do you need?

First, you'll need Visual Studio 2013.3 - that 3 means "Update 3" which is a free update.

  1. TRX - Task Runner Explorer Visual Studio Extension
  2. NPM/NBower Package Intellisense - Search for online NPM and Bower packages directly with Intellisense
  3. Optional Grunt Launcher (gives right-click options in Solution Explorer - including "npm install")
    • Without this extension, for now you'll need to run npm install yourself to restore/add packages.
    • If you DO have this extension, right click on packages.json and "npm install" before running a grunt/gulp task.

To open the TRX (Task Runner Explorer), simply right-click any gruntfile.js in your project:

image002 

The TRX sits at the bottom of VS by default and looks like this:

 image001

Here we can see that it found a gruntfile.js in the root of one or more projects in the solution. It also shows the task bindings feature that allows any task or target to be triggered by 4 different Visual Studio events.

To associate a task/target with a VS event, just right-click and setup bindings.

image003

To run any task/target, just double-click it and a console appears:

image004

When you've got the Package Intellisense Extension you'll find it easy to add and update packages when directly editing your package.json for both bower and npm.

completion-name

You'll even get metadata tooltips populated asynchronously.

tooltip-animated

As you go testing it, remember you'll need to run "npm install" before you use the Task Runner Explorer to run Grunt tasks.

Big thanks to Mads Kristensen, Dan Chartier, and Van Kichline for their great work on this feature!


Sponsor: Many thanks to Intersoft for sponsoring the feed this week! Enterprise cross-platform native apps development made painless with Intersoft Crosslight. Sounds too good to be true? See it for yourself and get started today! 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

ASP.NET vNext - August 2014 Status Rollup

August 29, 2014 Comment on this post [35] Posted in ASP.NET | Open Source
Sponsored By

Work on the next version of ASP.NET continues. It's a world of Alpha software, Git commits, breaking changes, and daily builds. If you're not one for risk, this blog post is for you. Read about all the fun stuff that's going on, and install nothing. If you do like a little spice in your life, jump in and install some early builds and join this active and opinionated community.

Introducing ASP.NET vNext

We announced vNext in May and did some great talks at TechEd.

ASP.NET vNext has number of notable features, including, but not limited to:

  • Open Source from the start and runs on Windows, Mac, and Linux.
  • No "build to disk" step, just refresh and go with runtime in-memory compilation from the Open Source Roslyn compiler.
  • Optional cloud optimized local install the CoreCLR that runs great in Azure.
  • Want to use a Mac and Sublime rather than Windows and VS? Sure.
  • No strong naming, no dependency on System.Web
  • Dependency injection everywhere
  • side-by-side runtimes (one app can't hurt another, get your own versions of everything)
  • NuGet Packages easy to bring in the new project.json system. But, you can also swap in the source for your favorite libraries!

 

David Fowler and Scott Hanselman

Since then we've seen the release of betas of the next version of Visual Studio, like Visual Studio "14" CTP 3. This version of VS includes the ASP.NET vNext alpha 3 packages plus initial tooling. The project system is changing and this VS14 build includes Intellisense for the new Project.json files.

  • ASP.NET and Web Development vNext Updates. This CTP includes all the Visual Studio 2013 Update 3 web tooling improvement and ASP.NET vNext alpha 3 runtime packages. It has improved tooling support for ASP.NET vNext, such as support for build configuration and support for unit tests, and it no longer includes content and compile items inside “.kproj” file. ASP.NET vNext includes an updated version of the RyuJIT JIT compiler. For details, please read the full post on the .NET Web Development Tools blog.

Separate from ASP.NET vNext, this build of VS14 also includes .NET Native, C++ updates, Shared Projects, as well as little things like retina icons for HiDPI displays.

Project.json files

Scaffolding for ASP.NET vNext

ASP.NET vNext is very modular and will include customizable command-line scaffolding . As with all of ASP.NET vNext, it's easy and alpha, but we've got blog posts up showing you how to get started with scaffolding. We've also got details on how to customize (of course) scaffolding for your personal needs.

ASP.NET vNext on a Mac

Sure, why not? We're working on a Sublime Text 3 plugin at https://github.com/ligershark/Kulture that means you'll be able to develop ASP.NET vNext apps in your favorite IDE. There's a quick YouTube video here.

ASP.NET on a Mac

There's also some clever community members with C# Intellisense working! The LEGO pieces are snapping together nicely.

Intellisense on a Mac

This is just a taste, there's more coming that WILL surprise you

What else is possible?

ASP.NET vNext going forward...Alpha 3

David Fowler has some great Alpha 3 details on his blog that cover some architecture changes and explains some choices. ASP.NET vNext apps get their own copy of the CLR/BCL when deployed, but this is a hassle when developing. So, ASP.NET vNext apps can use a Global NuGet repository (this is NOT the GAC, relax.)

Apps can also opt in to new C# 6 features easily with a quick change to project.json.

{
"compilationOptions": {
"languageVersion": "experimental"
}
}

Again, this is all happening in the open on GitHub at https://github.com/aspnet, so check out the last milestone's issues here: https://github.com/aspnet/KRuntime/milestones/1.0.0-alpha4

I'm sure I missed something. Sound off in the comments!


Sponsor: Many thanks to my friends at Raygun for sponsoring the feed this week. I *love* Raygun and use it myself. It's amazing. Get notified of your software’s bugs as they happen! Raygun.io has error tracking solutions for every major programming language and platform - Start a free trial in under a minute!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

How to run Background Tasks in ASP.NET

August 26, 2014 Comment on this post [41] Posted in ASP.NET | NuGet | NuGetPOW | Open Source
Sponsored By

A few years back Phil Haack wrote a great article on the dangers of recurring background tasks in ASP.NET. In it he points out a few gotchas that are SO common when folks try to do work in the background. Read it, but here's a summary from his post.

  • An unhandled exception in a thread not associated with a request will take down the process.
  • If you run your site in a Web Farm, you could end up with multiple instances of your app that all attempt to run the same task at the same time.
  • The AppDomain your site runs in can go down for a number of reasons and take down your background task with it.

If you think you can just write a background task yourself, it's likely you'll get it wrong. I'm not impugning your skills, I'm just saying it's subtle. Plus, why should you have to?

There's LOT of great ways for you to do things in the background and a lot of libraries and choices available.

Some ASP.NET apps will be hosted in IIS in your data center and others will be hosted in the Azure cloud. The spectrum of usage is roughly this, in my opinion:

  • General: Hangfire (or similar similar open source libraries)
    • used for writing background tasks in your ASP.NET website
  • Cloud: Azure WebJobs 
    • A formal Azure feature used for offloading running of background tasks outside of your Website and scale the workload
  • Advanced: Azure Worker Role in a Cloud Service
    • scale the background processing workload independently of your Website and you need control over the machine

There's lots of great articles and videos on how to use Azure WebJobs, and lots of documentation on how Worker Roles in scalable Azure Cloud Services work, but not a lot about how your hosted ASP.NET application and easily have a background service. Here's a few.

WebBackgrounder

As it says "WebBackgrounder is a proof-of-concept of a web-farm friendly background task manager meant to just work with a vanilla ASP.NET web application." Its code hasn't been touched in years, BUT the WebBackgrounder NuGet package has been downloaded almost a half-million times.

The goal of this project is to handle one task only, manage a recurring task on an interval in the background for a web app.

If your ASP.NET application just needs one background task to runs an a basic scheduled interval, than perhaps you just need the basics of WebBackgrounder.

using System;
using System.Threading;
using System.Threading.Tasks;

namespace WebBackgrounder.DemoWeb
{
public class SampleJob : Job
{
public SampleJob(TimeSpan interval, TimeSpan timeout)
: base("Sample Job", interval, timeout)
{
}

public override Task Execute()
{
return new Task(() => Thread.Sleep(3000));
}
}
}

Built in: QueueBackgroundWorkItem - Added in .NET 4.5.2

Somewhat in response to the need for WebBackgrounder, .NET 4.5.2 added QueueBackgroundWorkItem as a new API. It's not just a "Task.Run," it tries to be more:

QBWI schedules a task which can run in the background, independent of any request. This differs from a normal ThreadPool work item in that ASP.NET automatically keeps track of how many work items registered through this API are currently running, and the ASP.NET runtime will try to delay AppDomain shutdown until these work items have finished executing.

It can try to delay an AppDomain for as long as 90 seconds in order to allow your task to complete. If you can't finish in 90 seconds, then you'll need a different (and more robust, meaning, out of process) technique.

The API is pretty straightforward, taking  Func<CancellationToken, Task>. Here's an example that kicks of a background work item from an MVC action:

public ActionResult SendEmail([Bind(Include = "Name,Email")] User user)
{
if (ModelState.IsValid)
{
HostingEnvironment.QueueBackgroundWorkItem(ct => SendMailAsync(user.Email));
return RedirectToAction("Index", "Home");
}

return View(user);
}

FluentScheduler

FluentScheduler is a more sophisticated and complex scheduler that features a (you guessed it) fluent interface. You have really explicit control over when your tasks run.

using FluentScheduler;

public class MyRegistry : Registry
{
public MyRegistry()
{
// Schedule an ITask to run at an interval
Schedule<MyTask>().ToRunNow().AndEvery(2).Seconds();

// Schedule a simple task to run at a specific time
Schedule(() => Console.WriteLine("Timed Task - Will run every day at 9:15pm: " + DateTime.Now)).ToRunEvery(1).Days().At(21, 15);

// Schedule a more complex action to run immediately and on an monthly interval
Schedule(() =>
{
Console.WriteLine("Complex Action Task Starts: " + DateTime.Now);
Thread.Sleep(1000);
Console.WriteLine("Complex Action Task Ends: " + DateTime.Now);
}).ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);
}
}

FluentScheduler also embraces IoC and can easily plug into your favorite Dependency Injection tool of choice by just implementing their ITaskFactory interface.

Quartz.NET

Quartz.NET is a .NET port of the popular Java job scheduling framework of the (almost) same name. It's very actively developed. Quartz has an IJob interface with just one method, Execute, to implement.

using Quartz;
using Quartz.Impl;
using System;

namespace ScheduledTaskExample.ScheduledTasks
{
public class JobScheduler
{
public static void Start()
{
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();

IJobDetail job = JobBuilder.Create<MyJob>().Build();

ITrigger trigger = TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule
(s =>
s.WithIntervalInHours(24)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
)
.Build();

scheduler.ScheduleJob(job, trigger);
}
}
}

Then, inside your Application_Start, you call JobScheduler.Start(). There's a great getting started article on Quartz at Mikesdotnetting you should check out.

Hangfire

And last but definitely not least, the most polished (IMHO) of the group, Hangfire by @odinserj. It's a fantastic framework for background jobs in ASP.NET. It's even optionally backed by Redis, SQL Server, SQL Azure, MSMQ, or RabbitMQ for reliability.

The Hangfire documentation is amazing, really. Every open source project's document should be this polished. Heck, ASP.NET's documentation should be this good.

The best feature from Hangfire is its built in /hangfire dashboard that shows you all your scheduled, processing, succeeded and failed jobs. It's really a nice polished addition.

image

You can enqueue "fire and forget" jobs easily and they are backed by persistent queues:

BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget"));

You can delay them...

BackgroundJob.Schedule(() => Console.WriteLine("Delayed"), TimeSpan.FromDays(1));

Or great very sophisticated CRON style recurrent tasks:

RecurringJob.AddOrUpdate(() => Console.Write("Recurring"), Cron.Daily);

Hangfire is just a joy.

Check out the Hangfire Highlighter Tutorial for a sophisticated but easy to follow real-world example.

There's a rich ecosystem out there ready to help you with your background tasks. All these libraries are excellent, are open source, and are available as NuGet Packages.

Did I miss your favorite? Sound off in the comments!


Sponsor: Many thanks to my friends at Raygun for sponsoring the feed this week. I *love* Raygun and use it myself. It's amazing. Get notified of your software’s bugs as they happen! Raygun.io has error tracking solutions for every major programming language and platform - Start a free trial in under a minute!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

I was annoyed by the web font issues at Upworthy...you won't believe what I did next!

August 17, 2014 Comment on this post [11] Posted in HTML5
Sponsored By

Sorry about the title, I had to. ;)

I was running Windows and Google Chrome and I clicked on a link to an Upworthy.com video. When I go to Upworthy recently (don't judge me) I've been seeing this weird font for the last few months. It's obnoxious, and I was surprised they'd let this fly.

Upworthy has weird fonts

Later, though, I looked in another browser, and it looked fine.

Upworthy rendered in IE

Ok, time to F12. According to IE's Developer Tools there are three webfonts coming down and they each are downloading completely.

IE dev tools say the WOFF file is fine

Interestingly Chrome says the same thing:

Chrome agrees

What's the DOM expecting the font to be? Well, basically all of them. ;)

That's a long font-family

Seriously, though, IMHO pick a font or font family and move on. There's really no need to make a list of 11 font types in the order you'd prefer them. Either your web font works or it's Helvetica time.

Gill Sans? I don't see a Gill Sans available here. Gill Sans is a Mac OS X system font, but it seems that Google Chrome on Windows REALLY don't like being asked for it. ;)

I took each of the downloaded WOFF files and tried to open them at http://www.pkmurphy.com.au/glyphviewer/ to see if one was Gill Sans. Of course, none contained any of the first their fonts they're asking for. Unless you explicitly download a web font, a list of fonts like these are a just a designer's wish list.

Web Designers: Design for the web, not the cool fonts you have on your machine.

On 99% of Windows machines you're going to end up with Segoe UI with this CSS font-family as most folks won't have those first three fonts. It seems that Chrome gives up (?) after a few tries (not sure?) but if I remove Gill Sans as the first item it renders fine.

image

The font is correct with a smaller font-family

I tried to find a bug on this in the Chromium bug database...I'm not sure if it might be this one?

I hope a CSS person at Upworthy sees this and solves the mystery! What are your thoughts, Dear Reader?


Sponsor: And a big thanks to Raygun for sponsoring the feed this week! I love Raygun and use it on all my apps. Get notified of your software’s bugs as they happen! Raygun.io has error tracking solutions for every major programming language and platform - Start a free trial in under a minute!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Surface Pro 3 - Initial Impressions

August 15, 2014 Comment on this post [76] Posted in Reviews
Sponsored By

I went out and bought a Surface Pro 3. I bought the i7 8 gig RAM 256 gig storage version. It was paid for with my own money and there were no discounts. It's been a while since I had a high-powered laptop that was my own, not my employers, so I was mostly happy to spend the money. I bought the "Microsoft Complete" plan that covers accidental damage, even from drops.

That's a Surface Pro 3 there

I was a big fan of the size of the the Surface RT and the Surface 2. Those were the tiny thin ARM-based Surfaces. I used them all the time for email, Videos, browsing. I have an iPad Air, but used the Surfaces for their keyboard and their split screen abilities. Sitting on a plane with an 8 hour battery life device doing email and watching a movie at the same time is killer. If my iPad could do split screen that would be something.

I was NOT a fan of the Surface Pro 2. I have a lot of friends who have some but it was just so thick and heavy. The differential between the thickness of the keyboard and the thickness of the device itself was near comical. I wasn't going to try a Pro until it was as thin as a Surface 2.

And the Surface Pro 3 is thin. It's crazy thin. It's 9.1mm thick and about 800grams. That's about 1.8 lbs.

Now, I'm never going to be able to do a review like Paul Thurrott or AnandTech so I'd encourage you to read those uber-reviews. Instead, I'm going to cut through the specs and get to the questions and answers that matter to me.

Oh, and this is random as I'm not a sticker person. I have no stickers on any of my laptops but this Decal from DecalGirl was too awesome so I went all in.

What IS this device? The Obvious Comparisons

IMG_8260The difference between my Lenovo X1 Carbon and my iPad Air is clear. One's a powerhouse laptop and one is a lightweight tablet. I do work on the X1 and I surf and relax with the Air. I throw them both in my bag and go. I'll do a little light email on the iPad but it's largely my media and gaming device. They are separate and their difference makes sense to me.

After carrying the Surface Pro 3 around for a week, two interesting things happened. The screen on my iPad now feels small and the screen on my X1 seems HUGE. The Surface is basically the size and weight of a large magazine or a stack of papers.

The Surface occupies a space in my brain like a real hybrid. I want to throw the Surface on the couch with abandon like I do my iPad, but somehow I carry it with more reverence. That's likely because I didn't get the cheapest Surface. My subconscious knows it's a non-trivially-priced laptop rather than a tablet. 

I truly love my iPad Air. It works, it turns on, it runs one app at a time, and runs them well. I play games like Modern Combat with my Steelseries Stratus bluetooth controller and am amazed.

But then I plug the Surface Pro into my 30" monitor, add a keyboard, mouse, or an Xbox controller and play a Steam Game, and I realize this is an i7 PC. It's a weird shift that has taken me the week to get my head around.

The Good

From a consumers point of view (and in this context, that's me) it seems there are a lot of updates coming down for the Surface. Just yesterday an update came in that gave me more control over the touchpad and its right-click behavior. I hope that the updates continue. According to the Penny Arcade review they are looking at updates to improve the pen and other little details.

Can it run Visual Studio? Sure. I have been using it full time for a week and it's been fine. I wish it had 12 gigs of RAM, but I wish everything did.

The Type Cover 3 is WAY better than the Type Cover 2, and that one was pretty good. I thought the fold-up extra magnet was a gimmick but it's not. It does more than change the angle of the keyboard, it adds lateral stability to the device and makes it feel more like a laptop and less like a tablet with a keyboard attached.

The screen is fantastic. I mean, truly awesome. It's "retina" in that I can't see individual pixels and it's super bright and clear. The resolution on devices like the Yoga 2 Pro are so high that they can be overwhelming. The Surface Pro 3's 2160x1400 is such that I can run it at 100% (no scaling) and find it usable. I am running at 125% right now and am not having any of the high-dpi issues that happen when you scale out to 200%. It's also worth noting that you can scale the desktop and full-screen apps separately.

There is a micro-SD card slot hidden under the stand. I popped it a 64-gig card and told Windows to store videos there. Easy expansion and my movies take up no space on my main drive.

NOTE: Having a USB3 port is awesome, so I got a 3 port USB3 hub with Ethernet and it works great. I added a tiny Smart Card reader and a 3-in-1 mini DVI video adapter (DVI/HDMI/VGA) and got my bag of adapters down to just these three.

The Bad

Noting that I have an i7 version, and not the i3 or i5, I have noticed both fan noise and heat when the Surface Pro 3 is working hard. By working hard, I mean sustained CPU over 50-60% plus hard drive access plus wireless. So, playing Steam Games, installing Visual Studio, running Handbrake.

I was initially really disappointed that there was a fan at all. But again, after a week, I realized that the laws of physics are what they are and I'm carrying around an i7 the size of a paper notebook. I also went back to my X1 Carbon Touch and installed Visual Studio 2013.3 and noticed that the fan turned on noted it was hot too. In fact, hotter than I remembered.

So, is there a fan and will it blow when needed? Yes. I'm cool with it, because 90% of the time, it's off. It did take a mental adjustment.

Conclusion

I'm 90% happy with the Surface Pro 3. It's small and it's fast. It's not my desktop but it's definitely as fast as my beloved Lenovos when doing regular stuff. Right now I've got Outlook, Chrome, Firefox,  and IE all open. I've got 20+ tabs going, Windows Live Writer and an instance of Visual Studio. I've ordered the Docking Station and will report back when I've hooked it up.

Do any of you have a Surface Pro 3? What are your thoughts?


Sponsor: And a big thanks to Raygun for sponsoring the feed this week! I love Raygun and use it on all my apps. Get notified of your software’s bugs as they happen! Raygun.io has error tracking solutions for every major programming language and platform - Start a free trial in under a minute!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.