Starting with ASP .NET 5 (empty project) and static files.


If you are starting with ASP .NET 5 (1.0.0-rc1-final) and you just want to serve an “index.html”, you can follow these steps:

  • Start Visual Studio 2015
  • File > New > Project…
  • Installed > Templates > Visual C# > Web > ASP.NET Web Application
  • Choose .NET Framework 4.6.1



  • ASP.NET 5 Templates > Empty



  • Open project.json and add package dependency “Microsoft.AspNet.StaticFiles”: “1.0.0-rc1-final”:




  • Open Startup.cs and remove the app.Run lines:



  • In Startup.cs add the follwoing lines in the Configure methode beneath app.UseIISPlatformHandler();:
    • app.UseDefaultFiles();
    • app.UseStaticFiles();
  • Like so:




  • Add an index.html file to the wwwroot folder and add the text “Hello world from html” to the body:






Press F5 and the a browser should appear showing you the “Hello world from html”



Fix: TypeScript 1.7.6 compile on save in Visual Studio 2015 not working

I upgraded Visual Studio 2015 TypeScript extension to 1.7.6, then compile on save stopped working.

First I checked if “Compile on save” was enabled on my 4.5.2 web project properties (TypeScript Build tab):




Then I checked if “Automatically compile TypeScript file which are not part of a project” was enabled (Tools / Options).




Then the TypeScript files still would not compile on save (they were compiled, when the project was build, but not when a TypeScript file was saved.


The solution

I removed the following part in my Web.csproj file:


<PropertyGroup Condition="’$(Configuration)|$(Platform)’ == ‘Debug|AnyCPU’">
    <TypeScriptOutFile />
    <TypeScriptOutDir />
    <TypeScriptMapRoot />
    <TypeScriptSourceRoot />


Then I added a tsconfig.json file to the root of my project:




  "compilerOptions": {
    "noImplicitAny": true,
    "sourceMap": true,
    "target": "es5"




Don’t now if both steps are needed, but after that, my compile on save started working again.

Fingerprint bundles in path, not in query parameter with System.Web.Optimization and Visual Studio 2015

In my previous post ( I explained how to:

– create a new ASP .NET MVC 5 .NET 4.6 project in Visual Studio 2015

– add static caching, add url rewrites

– add fingerprinting to the “folder part” of each URL, to bust the client cache, when a new build is deployed to the website


Now if you don’t want to use the URL Rewrite approach, but you still want to fingerprint the “folder url part” of the bundels created with the System.Web.Optimization (instead of using the standard query parameter cache busting technique), you can use the following class:




Use this class, when the bundles are created and when they are used inside the *.cshtml:




Then inside a *.cshtml page:




In this way, only the “name” of the bundle is fingerprinted and bundeling will only take place in “release” build.

The System.Web.Optimization will take care of the “cache busting”, no need for “URL rewriting”.


The code uses the following extension method:



Cache busting / fingerprinting bundles with System.Web.Optimization and Visual Studio 2015

I like to use client build systems like grunt, gulp, webpack etc. to bundle and minify JavaScript and CSS files, but on a resent project I had to use the Microsoft Web optimization framework.


Note: All code used in this blog post  can be found at:


In this I will describe how to create an MVC .NET 4.6 web application, that uses bundeling, minification and fingerprinting for cache busting all by using the System.Web.Optimization framework.


Start Visual Studio 2015, then click:

File> New > Project…


Choose: Installed\Templates\Visual C#\Web\ASP.NET Web Application



Choose: “ASP.NET 4.6 Templates”: “Empty” and “Add folders and core references for”: “MVC”




Add a “MVC 5 Layout Page (Razor)” called “_Layout” to the “Views” folder






Add a “Home” controller to the “Controllers” folder:



Choose: MVC 5 Controller – Empty




Add a “Index.cshtml” view to the /Views/Home folder:




Choose the “_Layout.cshtml” as “layout page”




Change html:




Add some TypeScript files and CSS files to the /Views/Home folder:








To allow static file content serving from the “/Views” folder adjust the Web.config inside the “/Views” folder, remove the “BlockViewHandler”:


Add the System.Web.Optimization NuGet package to your project:




Search for “Optimization” and choose: Microsoft.AspNet.Web.Optimization




This will install the following dependencies to your project:




After installing the package we will first upgrade some of the components, just change the filer to “Upgrade available”:




Upgrade all packages until all package are upgraded:



Add a NonOrderingBundleOrderer.cs class to the “/Common” folder.

This class will prevent automatic ordering of the files inside the bundle.

The files will be placed in the html in the order they are added to the bundle.




Add a BundleConfig.cs class to the “App_Start” folder




Change code like:

The “#if !DEBUG”, means:

In “debug” modus all files are rendered separately to the HTML in “release” modus all JavaScript files are combined to one JavaScript file and all CSS files are combined to one CSS file.



Change the global.asax

Add “BundleConfig.RegisterBundles(BundleTable.Bundles);”



Add a class “AssemblyExtensions.cs” to the “/Extensions” folder:



Edit code like:




Add a class “Bundle.cs” to the “/Common” folder:



Edit code like:



Change the “_Layout.cshtml” like:

The layout page contains the actual rendering of the CSS and JavaScript bundles.



When we run the application at this point we get 4 errors in the Browser console, because all JavasScript files and CSS files are fingerprinted with a version number and do not exist on disk:




To solve this error, we can add Url Rewriting to our Web.config file and start caching files:


To start caching files, add the following xml to the Web.config:





URL Rewrite extension

To start using Url Rewriting, first install the URL from or from the web platform installer inside IIS.

Note that URL Rewriting will work out of the box with IIS Express in Visual Studio 2015.




Then add the following to the Web.config:




All url’s that start with vx.x.x.x/ will be rewritten (the version number will be removed from the URL before passing it to the reset of ASP .NET. Only the part after the first “/” will be presented to the “match” rule.

So only the part “v1.0.0.0/View/Home/Test1.js” of the url http://localhost:4567/v1.0.0.0/View/Home/Test1.js will be passed to the match rule, that’s why the regex can start with a “^”.


Now when you run the application in debug modus you will see:




And when you run in “release mode” you will see:



As you can see the System.Web.Optimization framework automatically adds a “cache busting query parameter”, but in some browsers this is not enough, that’s why we added a version number inside the “folder” part of the url.



The final project structure should look like:




For more resources see:




If you use “URLs” inside a CSS file, that is added to a bundle, e.g.

background-image: url(;

Then these URLs should also be fingerprinted.

To fingerprint these URLs you can write a custom BundleTransform:


Or use the

This extension to the System.Web.Optimization framework, supports automatic transformation of relative paths to absolute paths in CSS-code (by using UrlRewritingCssPostProcessor).

Fix: Visual Studio 2013 / 2014–SQL Server 2014 – The term ‘Invoke-Sqlcmd’ is not recognized as the name of a cmdlet



When you want to run / edit / debug PowerShell scripts inside Visual Studio 2013 / 2015 you will have to install the “PowerShell Tools for Visual Studio” Visual Studio extension found at:


I wanted to run and debug a PowerShell script inside Visual Studio 2013 / 2015, on a machine that only had SQL Server 2014 installed as database server. This threw an exception: The term ‘Invoke-Sqlcmd’ is not recognized as the name of a cmdlet


Turns out you have to update the PowerShell “PSModulePath”, so it can find the PowerShell modules containing the SQL Server 2014 cmdlets.


Temp fix:

Existing Powershell session isn’t aware about Sql’s modules that were just installed. Take a look at environment variable $env:PSModulePath. Compare new shell’s variable to existing and you should see a missing path like …\Microsoft SQL Server\110\Tools\PowerShell\Modules\.
For a work-around, modify the path to include module dir. Like so,

$env:PSModulePath += ";C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules"


If you want to persist this extra “Module load path”, you have to change the registry:




Now I can run and debug the following PowerShell script inside Visual Studio 2013 / 2015:

# This sccript requires the system to allow running powershell scripts, when not allowed the following code can be used to allow running powershell scripts.
# Set-ExecutionPolicy RemoteSigned

# The following import statement enables the SQL Server PowerShell cmdlets, like "Invoke-Sqlcmd".
Import-Module SqlPs

$serverInstance = "(localdb)\v11.0"
$database = "App"

function ExecuteSqlFile {
    [string]$file = $args[0]
    Invoke-Sqlcmd -ServerInstance $serverInstance -Database $database -InputFile $file


Move C:\ProgramData\Package Cache\ to D:\

Windows with a couple of development tools takes up about 126GB of my 128GB SSD, to free-up some space I followed the guide at:


Then I moved the "C:\ProgramData\Package Cache" used by Visual Studio to D:\.


I did this by following the instructions at:


1. Move folder from C:\ProgramData to D:\ProgramData

This must be a move of the complete “Package Cache” folder, so after move you will have a folder C:\ProgramData, that does NOT contain the folder “Package Cache”.

2. Create a filesystem junction: mklink /J "C:\ProgramData\Package Cache" "D:\ProgramData\Package Cache"

This will create a filesystem junction, that will point all software that wants to access  "C:\ProgramData\Package Cache" to "D:\ProgramData\Packa Cache".


That alone saved me about 6GB.

How to Fix: No “organize usings” and F12 “Go to definition” disabled or grayed out in Visual Studio 2013

When I right clicked on my using statements in a C# file, the context edit menu, didn’t contain the options for refactoring and “organize usings” and the menu item “F12 Go to definition” was grayed out.

I found the fix at:


  • Clean your solution
  • Close solution
  • Remove any [solution].ncb, [solution].suo, [solution].vspscc files
  • Reopen solution
  • Rebuild solution

Menu options should appear and be enabled.

Awesome: Visual Studio will minify a css file automatically, when original file is altered.

I Just discovered that Visual Studio will automatically re-minify a css file, when the original not minified version is altered.

So I have two file: in a folder including the map files:





When I change the test.css the test.min.css is automatically overwritten by a new minified version.


Microsoft Visual Studio 2013 Update 4 RC

Microsoft Visual Studio 2013 Update 4 RC can be downloaded at:


It contains many new features for an update:


The thing I like the most:


Support for custom elements, polymer-elements and attributes

We no longer validate unknown attributers for custom elements as there will be many custom made tags in different frameworks. So there will no longer be squiggles under the unknown elements.