All posts by knarfalingus

ASP.NET 5 RC1 On Linux – INFO

Before I reset, I decided to lay out some basic info about ASP.NET 5

The current released (at present RC1) bits can be retrieved from

https://get.asp.net

Any bugs/issue or qualms should be posted to the appropriate repository on Github
https://github.com/aspnet

Recordings of the ASP.NET team standups can be found at

https://live.asp.net

The documentation (in progress) can be found at

https://docs.asp.net

Note any docs with a wrench icon has not been started yet.

There is also a freely available Microsoft Virtual Academy course available:

https://mva.microsoft.com/en-US/training-courses/introduction-to-asp-net-5-13786

ASP.NET 5 RC1 On Linux – Intermission

Well, in my last post I mentioned a Powershell/DNX case sensitivity issue related to commands. I logged this as an issue over on GitHub and was told that DNX,DNU and DNVM will be retired in RC2 in favor of a unified “dotnet” CLI (ETA February 2016). I had heard about these being possibly being replaced a few months ago at a regional .NET event, and also Scott Hanselman mentioned the new CLI last week on his blog

It’s possible to start try out some of these bits now so I will try re-starting with that in a future post (soon!).

ASP.NET 5 RC1 On Linux – Part IV – First App Analysis

Looking at the project.json from my last post

We see the following

{
  "version": "1.0.0-*",
  "description": "ConsoleApp1 Console Application",
  "authors": [ "knarfalingus" ],
  "tags": [ "hello", "world" ],
  "projectUrl": "https://www.knarfalingus.com",
  "licenseUrl": "https://opensource.org/licenses/MIT",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
  },

  "commands": {
    "ConsoleApp1": "ConsoleApp1"
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
       "Microsoft.CSharp": "4.0.1-beta-23516",
       "System.Console": "4.0.0-beta-23516",
      }
    }
  }
}

To simplify, we can actually remove the following

  "compilationOptions": {
    "emitEntryPoint": true
  }

This wasn’t required as the runtime will find the static Main() method.

Also we can remove the metadata, authors, projectUrl and licenseUrl etc. I added those arbitrarily anyway.

What is interesting is the commands

  "commands": {
    "ConsoleApp1”: “ConsoleApp1”
  }

The above is typical of what Visual Studio 2015 would create. The name “ConsoleApp1” doesn’t have to match the application/namespace, for example the following works just as well.

  "commands": {
    “xyz”: "ConsoleApp1”
  }

This can be explicitly run by executing

dnx xyz

The surprising part I found when trying this on Windows was, the value “ConsoleApp1” refers to the folder the app is in, not the namespace or application title. For example with this project.json

{
  "version": "1.0.0-*",

  "dependencies": {
  },

  "commands": {
    “xyz”: "ConsoleApp1"
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Console": "4.0.0-beta-23516",
      }
    }
  }
}

And the two files, project.json and Program.cs in a ConsoleApp1 directory, if I change into the directory from the parent directory using cd ConsoleApp1, dnx xyz works but if I do cd consoleapp1, in Powershell it doesn’t!, Powershell introduces case into the folder name see below. This doesn’t happen with the standard console.

Powershell can introduce case sensitivity issues when combined with commands

I am not sure if this is a bug or not due to the fact that ASP.NET is targeting systems with case sensitive file systems whereas in Windows the file system is not case sensitive (by default).

ASP.NET 5 RC1 On Linux – Part III – First App (Console)

Now that we have the VM set up, and ASP.NET 5 installed, lets do the bare minimum and create a console app.  In terminal type the following commands to create a folder for our project (you can create in an alternate location if you wish)

cd ~
mkdir Code
cd Code
mkdir ConsoleApp1
cd ConsoleApp1

Then fire up an editor, in this case I use nano (sadists can use vi)

nano

Let’s start with the C# program, enter the following code:

using System;

 namespace ConsoleApp1
 {
         public class Program
         {
                 public static void Main(string[] args)
                 {
                         Console.WriteLine("Hello World");
                 }
         }
 }

Now save the file as Program.cs

Fire up the editor again and create the project file:

{
  "version": "1.0.0-*",
  "description": "ConsoleApp1 Console Application",
  "authors": [ "knarfalingus" ],
  "tags": [ "hello", "world" ],
  "projectUrl": "https://www.knarfalingus.com",
  "licenseUrl": "https://opensource.org/licenses/MIT",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
  },

  "commands": {
    "ConsoleApp1": "ConsoleApp1"
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
       "Microsoft.CSharp": "4.0.1-beta-23516",
       "System.Console": "4.0.0-beta-23516",
      }
    }
  }
}

Save this file as project.json

Now we execute the following command to pull in the dependencies (Microsoft.CSharp and System.Console in this case). This will pull in quite a bit of files

dnx restore

If your project.json is incorrect in any way you will be greeted with stack traces. Scroll up and start from the top.

After all the dependencies have been pulled in you can execute the program:

dnx run

The output should be

Hello World

References : http://docs.asp.net/en/latest/dnx/console.html

ASP.NET 5 RC1 On Linux – Part II – Installation

Using the instructions from docs.asp.net, for Ubuntu we essentially run:

login to ubuntu
fire up terminal (Ctrl-Alt-T)

run the following commands:


sudo apt-get install unzip curl

curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh

sudo apt-get install libunwind8 gettext libssl-dev libcurl4-openssl-dev zlib1g libicu-dev uuid-dev

dnvm upgrade -r coreclr

sudo apt-get install make automake libtool curl
curl -sSL https://github.com/libuv/libuv/archive/v1.4.2.tar.gz | sudo tar zxfv - -C /usr/local/src
cd /usr/local/src/libuv-1.4.2
sudo sh autogen.sh
sudo ./configure
sudo make
sudo make install
sudo rm -rf /usr/local/src/libuv-1.4.2 && cd ~/
sudo ldconfig

Happily, this all ran without a hitch.


References: http://docs.asp.net/en/latest/getting-started/installing-on-linux.html#installing-on-debian-ubuntu-and-derivatives

ASP.NET 5 RC1 On Linux

Since the ASP.NET 5 Release Candidate 1 was released in late November, I’ve decided its time to give it a whirl, and to get around to doing some blogging.

Testing it out on Windows 10 would be the easiest course of action I suppose, but I’ve decided to give it a try on Linux, specifically the Ubuntu distro, as the big story with the new ASP.NET is the cross-platform capabilities.

For testing I created a second generation VM in HyperV, allocated the machine 8GB of RAM (dynamic), and set the max size on the virtual drive to be 64GB, and allocated two virtual processors.  This should be more than enough for a  test drive.

I then downloaded Ubuntu 14.04.3 Desktop LTS, and installed, essentially with the defaults.   Also, secure boot needed to be disabled to install Ubuntu on the second generation VM.

Next post, setting up ASP.NET 5 RC 1.

 

Test of Typescript SyntaxHilighter 1.5

 

//#region person class
class Person {
  @memoize('test')  //Typescript 1.5 decorators
  get name() { return '${this.first} ${this.last}'; }
  //test
  set name(val) {
    let [first, last] = val.split(' ');
    this.first = first;
    this.last = last;
  }
  greeting: string;
  constructor(message: string) {
    this.greeting = message;
  }
  //test of comment with a > and a < in it. Plus a #. Plus @test2
  greet(@anotherDecorator z : string) : string {
    var x = greeting || test;
    var t = 12 + 3;
    var b = !!x;
    $(".js-alert-link").on("click", (event:JQueryEventObject) => this.startTimer(event));
    return "Hello, " + this.greeting;
  }
}
//#endregion


YUI COMPRESSOR SINGLE FILE GENERATOR FOR VS2013

In the past I used a Javascript and CSS minifier in Visual Studio that I built on top of the original YUI compressor.  I implemented it via a Custom Tool / Single File Generator.  I figured this might be helpful with minifying the output of TypeScript.  I wanted to eliminate the Java dependency however, so  I built the generator on top of YUI Compressor.NET.  Unfortunately, this doesn’t seem to work for my situation.  When TypeScript generates new Javascript output it doesn’t seem to trigger the SFG to do its thing.   In any case I put the source on Github for anyone who is interested.

IIS REWRITE II – CURSE OF THE 500 URL Rewrite Module Error.

A few months back I wrote about how I set up the URL rewriting for this blog.   About two weeks ago I read some chatter on Twitter about using Dareboost to optimize one’s blog.  It had several recommendations when I ran it on my site, one of them being to enable IIS compression.  After some fiddling about I got it to work on my shared hosting plan, and thought nothing else of it.

Fast forward to today and I notice one part of my site isn’t working – the date picker on my very simplistic Amortization calculator isn’t working.  Well the problem turned out to be, the rewriting rules I had set weren’t covering links to CSS and Script.  Easy enough – I’ll just quickly add an extra outbound rule to cover this.   Well, every time I added a rule it either caused the entire site or the calculator to return empty responses, which I determined were due to HTTP 500 errors.  I couldn’t understand why adding a simple new rule was causing this, even when I modified it to take no action. 

It turns out the problem was this – and it makes sense – you can’t have an outbound rule if you have compression enabled.  IIS rewrite can’t scan for links, anchors etc. in the response if the content is compressed.  But it would be great if it could somehow alert you why this is happening or perhaps inspect the site configuration and display a warning when you open the URL rewrite feature in IIS Admin.