Windows 8 introduced WinRT(Windows Runtime) that allows us to develop applications based on C++, C#, Vb and JavaScript by allowing access to its Api and by allowing communication between different programming languages. Communication between languages is possible through Windows Runtime Component that creates WinMD Assembly. WinMD Assembly is a Assembly that contains metadata but can also contain types.

When you try to create Windows 8.1 store app you cannot add usual Class Library, you have to add Windows Runtime Component and there you can write your usual code.

Trying to add Class library to your Store App will result in “Unable to add a reference to project” error.

WinMD limitations (copied from https://www.microsoftpressstore.com/articles/article.aspx?p=2199428&seqNum=3):

  • The fields, parameters, and return values of all the public types and members in your component must be WinRT types.
  • Public structures may not have any members other than public fields, and those fields must be value types or strings.
  • Public classes must be sealed. If your programming model requires polymorphism, you can create a public interface and implement that interface on the classes that must be polymorphic. The only exceptions are XAML controls.
  • All public types must have a root namespace that matches the assembly name, and the assembly name must not begin with “Windows.”

Why would I need to create WinMD class library?

Lets explore it through Windows store app example.

Create new Solution and there add two Blank App.s for Windows 8.1 (one for C# and another for JS).

Both of these apps should have:

2x Textbox

1x Label

2x Button

Goal of this Application is to create Application where you can input data inside two different TextBoxes and combine their values inside Label after clicking button. Second goal is to copy some text value in your clipboard(simply copy some text with Ctrl+C) and display value in Label after clicking second button.

All this code can be easily achieved by writing it in backend of MainPage.xaml.cs file or inside JavaScript function, but we want our Application to share code, and that is here WinMD steps in. You can create methods that perform that actions and reuse it across different applications and different languages. Yup, even JavaScript can use WinMD classes written in C#.

Example of WinMD / Windows Runtime Component Assembly

MainPage.xaml

default.html

MainPage.xaml.cs – Buttons

Windows Runtime Component – Helper class

If you wish to inspect entire solution , download it from this link.

Please do not use code from solution  for your projects because no checks were implemented what so ever.