Using .NET Native on Windows Phone 8.1 Projects

EDIT: Found a tiny issue with my .NET Native script for WP 8.1 You HAVE to run powershell from within the Developer Command Prompt for VS 2013 (make sure you are running as admin), THEN run the powershell script. I didn’t realize that I had made this script from within that environment and noticed that the essentially environment variables that I am using weren’t there when calling PS regularly.

 

In April, Microsoft released a preview of a framework for Windows Store apps that would convert .NET assemblies into the compiled native binaries of the target architecture (x64/ARM for now) in order for application optimization. This tool was named, .NET Native.

This tool itself will help protect your code and IP (a.k.a make it even harder for people to reproduce your code, but not impossible) and also increase the application’s performance.

Getting Started: 

To download .NET Native, Go to the home page and register/download the preview. Close all instances of Visual Studio 2013 (VS 2013 Update 2 is required) then run the installation package.

The .NET Native tools are configured to purely work with Windows Store apps only, but I figured that it SHOULD work with Windows Phone 8.1 projects since they both use WinRT (mostly). I decided to come up with a solution that would enable .NET Native for Windows Phone 8.1 projects manually since there’s no way to enable it from Visual Studio.

Here’s the PowerShell script that runs this. BE SURE TO RUN AS ADMINISTRATOR 

I’ve tested this with VS 2013 Ultimate Update 2 running on Windows 8.1 Update 1 with the English language.

The syntax is as follows:

./enableProjectN.ps1 -solution “c:\pathtovsproject\wp81solution.sln”

The script will go through and determine whether you have VS 2013 installed, and whether the projects in your solution are WP 8.1 projects. It will then add the project config nodes that enable .NET Native.

For this to work, you MUST target your projects to the Release|ARM configuration in Configuration Manager.

The building of your project will take a little longer since it is running all of the tools to compile your C# into the native binaries . The file size will go up exponentially, but the app will run faster.

Read through the Compiling for .NET Native page for complete information on how the .NET Native technology works and for any gotchas.