How to configure .net native in Visual Studio 2015?

qpator picture qpator · Aug 13, 2015 · Viewed 11.9k times · Source

I read this guide for .net native, but I can't found 'Enable for .net native' in popup menu. Should I install some extra plugin for VS2015 for compile with .net native?

Answer

Hans Passant picture Hans Passant · Aug 14, 2015

[enter image description here

This is the Project + Properties, Build tab of a project that was created with one of the Project > New > Visual C# > Windows > Universal project templates. Your machine must boot Windows 10, you may need to download the SDK separately if you installed VS2015 before Win10. Red arrows indicate the important parts, it should only be enabled for the Release configuration. The Platform setting matters as well, you need to test this for all platforms you wish to support (ARM, x86, x64).

Emphasis on the word test. The only reason you have the .NET Native toolchain on your machine is to verify that your app still operates correctly after the Store server recompiles the package you submitted. It is rather imperfect and cannot handle every possible Universal app. Several pain points, the major one is Reflection. The toolchain cannot see any types you load with reflection so cannot know that these types need to be converted to native code as well. Your app will fail miserably on the user's machine if this isn't taken care of.

Testing is simply a matter of running the Release build of your program through its paces, verifying that everything still works correctly. Start with the x86 platform first. You can cut a few corners when you next test x64 and ARM.

The package you actually submit to the Store is the one that is not built with .NET Native. Microsoft wants to keep the option open to improve the toolchain so needs the MSIL version of your assemblies. Version numbering matters, the last digit is reserved for the store. They'll increment it when they rebuild your app.

In case it wasn't clear yet: the .NET Native toolchain is only available for Universal apps that are distributed through the Store. Maybe it will be usable some day on regular apps but that day is far off, a fundamental different way to package such apps will have to come first.