TypeScript 2 has been released

TypeScript 2 has been released (to be exact: version 2.0.3).

 

As by TypeScript 2.0 is now available!, the principal innovations are:

  • Definition file acquisition via npm
    This change is in line with the new Microsoft guideline to use npm (or bower) to acquire client side libraries (and still use NuGet for server side packages); it is also coherent of letting users leverage the TypeScript language even on non-Windows computers, in particular on Mac and Linux, where you can use Visual Studio Code
  • Non nullable types
    It's confirmed that this is a breaking change, so you have to set strictNullChecks to true in your tsconfig.json (by default it is false). Clearly it's strongly suggested to do so
  • Control Flow Analyzed Types
    Even more expanded from what already available in TypeScript 1.8
  • Readonly modified
    Similar to what available in C#

An even more detailed list of the language innovations is in What's new in TypeScript. And also give at look at the Breaking Changes.

 

Finally: you can start using it in Visual Studio 2015 downloading the TypeScript for Visual Studio 2015 plugin (it requires the Update 3).

Xamarin: adding Android components with problems

Working on a Xamarin project, I have added a component but I had some problem: the component was downloaded, but the dll was not referenced in the project.

I have found the explanations of the guide Walkthrough: Including a Component in your project, but it must be something simple because I add the component inside Visual Studio 2015.

Then I've found the help Quick work around for unresolved Xamarin components in Visual Studio, and I thought that this could be the case, but the files were already on the disc so the issue was not about the path length.

In the end the component was badly downloaded on the first instance, and I had to:

  • remove the components from my project
  • remove the NuGet packages related to the components from my project (founding this took me really a lot of time...)
  • clear the Components folder at the solution level
  • clear the Packages folder at the solution level

VS2015 Android emulator: multiple issues

Visual Studio 2015 introduces the new Android emulator. What is great is that it is based on Hyper-V technology, so hardware virtualization, as described more extensively in Introducing Visual Studio’s Emulator for Android.

Using it to develop Xamarin application, I've run into some issues, and I think that it would be good to collect them here:

  • first of all, during my first attempt to run it to debug a simple application, I got in the Output windows of Visual Studio this cryptic error:
         In mgmain JNI_OnLoad
         
    Couldn't connect to logcat, GetProcessId returned: 0
    As described in 
    Can't run app on Visual Studio 2015 emulator (DWP Handshake failed), the solution is to go to the Android project settings and in the Android Options tab, disable Fast Deployment
  • the second problem was that because of my naming convention for demo projects, I had a too long project name.
    Doing some attempts, I've verified that the longest project name you can give is 37 characters (more create problems with the deployment);
  • when I've been finally able to run my application, I've noticed that I had multiple graphic issues (even if the application is really basic).
    As described in Visual studio android emulator will not start fully, you have to go to the folder C:\Program Files (x86)\Microsoft XDE\10.0.10240.0\SKUs\Android, edit the file xdesku.xml and delete/comment the line:
         GuestDisplayProvider="VsEmulator.OpenGLGuestDisplay"

C#: automated method caller information via attributes

In C# there is a feature of the language that allows a method to receive as input parameters the member name, file path and line number of the calling method/property.

It is enough to add attributes to the method parameters receiving these values, as in the following example:

public void DoProcessing()
{
    TraceMessage("Something happened.");
}

public void TraceMessage(string message,
        [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
        [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
        [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
{
    System.Diagnostics.Trace.WriteLine("message: " + message);
    System.Diagnostics.Trace.WriteLine("member name: " + memberName);
    System.Diagnostics.Trace.WriteLine("source file path: " + sourceFilePath);
    System.Diagnostics.Trace.WriteLine("source line number: " + sourceLineNumber);
}

You can see that this feature can be particular useful during tracing.

The example above has been taken from Caller Information (C# and Visual Basic).

PowerShell: edit and debug ps1 files in Visual Studio

In Visual Studio it's possible to edit and debug PowerShell scripts, using the PowerShell Tools for Visual Studio 2015 extension.

But even after installing the extension, debugging doesn't immediately work, as trying to do this, the output window simply shows an unauthorized access error message.

I've found the blog post PowerShell Tools for Visual Studio 2013 – unable to run and/or debug PowerShell script – execution policies problem that has helped me in finding the solution:

  • from a PowerShell window with elevated privileges,
  • run the command "Set-ExecutionPolicy" RemoteSigned