The WinRT platform provides developers with a new way to build reusable software components. WinRT types packaged in a WinRT component, also called a WinMD component (WinRT components == WinMD components). In traditional .NET application development, you could create a dynamic-link library (DLL) as a managed class library and use it in one or more applications.
This option is still available in Visual Studio. However, you can change the output type of a library project from class library to WinRT component, and the output of such a project is a WinMD (Windows Meta Data) file.
Benefits of creating a WinMD / WinRT component.
But this flexibility comes with some restrictions.
- All public classes in WinRT / WinMD component should be marked sealed.
- public fields aren’t allowed.
- public data members must be declared as properties
- Data types should be WinRT / WinMD compatible
- Creating a WinRT / WinMD component in C++ has some additional property attribute settings (activatable class and ect…)
Creating a WinRT / WinMD component in C#
This is a very simple example and straight forward create Windows Store Apps (WSA) class library. Mark the class public and sealed. Create a method to return a string value.
Go to Project Properties and change the output type from Class Library to Windows Runtime Component.
Do the build.
Run the code. 🙂
Things to consider