Tuesday, October 21, 2014

TFS Performance Tips

Last week I noticed the following blog post by Cory House; Two Quick TFS Performance Tips.

It’s a small post, but one with great value…

In his post, he shares one of the greatest performance tips ever about TFS; create a separate workspace for each Team Project. How many times I heard a developer complain that TFS was slow and cumbersome to use… And when I took a look at his Visual Studio solution I had to discover that his 5 years of developer work was all sitting in the same workspace. Ugh…

tortoise_and_hare

Monday, October 20, 2014

Announcing Microsoft Connect event

On November 12th,  Microsoft is hosting an online developer event called Connect();Connect(); will be a chance to have a conversation with developers about what’s coming next for developer tools, developer services and application platforms across Microsoft.

From the website:

Connect(); is a cloud-first, mobile-first, code-first virtual event focused on current and future Microsoft technologies for developers. Build on your current skills, unleash your creativity, and expand what's possible to deliver unprecedented innovations.”

connect-2

So if you have any questions about what’s coming next in ASP.NET, this is a great opportunity to get some answers…

Friday, October 17, 2014

Angular.js: Using ngAnnotate inside Visual Studio

Last week I discovered a great NPM module; ‘ng-annotate’.It adds and removes AngularJS dependency injection annotations.

The great thing is that allows you to use implicit dependencies in Angular.js and ng-annotate will automatically make the switch to the Inline Array annotation.

This means that you write  the following code:

And that it gets rewritten automatically to:

The only problem is that I have to run ngAnnotate from the commandline. As a Visual Studio user, I would like to have an integrated solution. Let’s see how we get this done…

Integrate ngAnnotate into Visual Studio

To make integration possible, we’ll use some Visual Studio Extensions. So let’s install them first.

  • Start with installing(or upgrading) to the latest version of Web Essentials.
  • Also install node.js on your system.
  • Now it’s time to install Task Runner Explorer. This will allow you to run Grunt and Gulp tasks directly from within Visual Studio.
  • You can also install the Package Intellisense plugin. This is not required but makes it a little bit easier to use NPM from inside Visual Studio.

Now that we have all prerequisites installed, it’s time to get back to ng-annotate. There exists a ng-annotate plugin for both Grunt and Gulp. Which one you use depends on your own preferences but the process is similar. I will show you how to do it using Grunt. But first we have to install Grunt itself:

  • Open a command prompt and install the Grunt command line interface globally by using the following command:
    • npm install -g grunt-cli

Open your web project inside Visual Studio. It’s time to add some extra files:

  • Add a package.json file to the root of your web project. Also add a gruntfile.js file.

image

  • Inside the package.json, add the following content. In this case I also added a dependency to some other NPM packages to minify and uglify my code:
  • Right-click on the package.json file and choose NPM install packages. (If you don’t see this option, open a command prompt and do an npm install from the package.json location).

image

  • After the packages are installed, it’s time to create our gruntfile.js:

 

We finally arrived at the moment where we can run the Task Runner Explorer:

  • Right-click on the gruntfile.js in Visual Studio and choose Task Runner Explorer.

image

  • This will open up the Task Runner Explorer and show all available Grunt tasks.

image

  • Right click on the ngAnnotate task, choose Bindings and click on After build. Now each time we build the ngAnnotate task will automatically rewrite our Angular.js code to add the missing annotations.

image

Great!

Thursday, October 16, 2014

Angular.js 1.3: The ng-strict-di directive

Angular.js 1.3 introduces a new directive: ‘ng-strict-di’.

<div ng-app="myApp" ng-strict-di>

From the documentation:

if this attribute is present on the app element, the injector will be created in "strict-di" mode. This means that the application will fail to invoke functions which do not use explicit function annotation (and are thus unsuitable for minification), as described in the Dependency Injection guide, and useful debugging info will assist in tracking down the root of these bugs.

To explain this a little bit more; Angular.js does (implicit) dependency injection based on the name of the object you try to inject. So if you specify a parameter as ‘$scope’ it will look for an object called ‘$scope’. This works great until you start using minification. When you minify your JavaScript, the function parameters are shortened to a random letter, e.g. ‘d’. When the injector runs this minifies JavaScript it no longer searches for a ‘$scope’ object, but for a ‘d’ object instead. As this object does not exists, dependency injection will fail.

A solution for this is explicitly specifying the dependencies as strings(called explicit function annotation). The ‘ng-strict-di directive’ will check if this syntax is used and throw an exception otherwise.

You can use the $inject Property annotation or use the Inline Array annotation:

Wednesday, October 15, 2014

Another free Xamarin e-book

There is really no excuse anymore to at least read one book about Xamarin. After the free ‘Master Cross-Platform Mobile Development with Xamarin ebook’ I mentioned last week, there is now another free ebook: Creating Mobile Apps with Xamarin.Forms, Preview Edition: Cross-platform C# programming for iOS, Android, and Windows Phone, by Charles Petzold. This ebook was created jointly by Xamarin and Microsoft Press.

XamarinEbook

This Preview Edition ebook is about writing applications for Xamarin.Forms, the new mobile development platform for iOS, Android, and Windows Phone unveiled by Xamarin in May 2014. Xamarin.Forms lets you write shared user-interface code in C# and XAML (the eXtensible Application Markup Language) that maps to native controls on these three platforms.

This ebook is a Preview Edition because it's not complete. It has only six chapters. We anticipate that the final version of the book will have at least half a dozen additional chapters and that the chapters in this Preview Edition might be fleshed out, enhanced, or completely reconceived. The final edition of the book will probably be published in the spring of 2015.

You can download PDF and Mobi formats at the Microsoft Virtual Academy.

Tuesday, October 14, 2014

Log database activity in Entity Framework

A quick tip if you want to log what’s going on inside Entity Framework:

This will log not only the query, but also other useful information like the execution time, etc…

Monday, October 13, 2014

Fake asynchrony: Avoid the JSON.NET async APIs

As a developer I frequently build my own libraries or re-use existing ones. In the new async/await world, you have to consider if you implement an async version of your library.  However one thing that is important is to avoid “fake asynchrony”. Fake asynchrony is when a component has an async API, but it’s implemented by just wrapping the synchronous API within a task or thread.

This will lead to unexpected behavior and can decrease performance. One example of fake asynchrony is Newtonsoft JSON.NET, the known (and great) JSON serialization library. The creators of JSON.NET are already aware of this issue and made the async API’s obsolete:

image