When I saw the new project dialog for Windows Store Apps or Windows 8 Apps, I had a problem. What is the difference between a Class Library project vs. Windows Runtime Component project.
Even the description within Visual Studio was not that clear:
A project that creates a managed class library for Windows Store apps or Windows Runtime components.
Windows Runtime Component
A project for a Windows Runtime component that can be used by Windows Store apps, regardless of the programming languages in which the apps are written.
This was what I found on the web:
A Class Library (Windows Store apps) project is a DLL that can be used by Windows Store apps written in .NET languages only. The critical difference – no metadata file is created, so this cannot be used with other languages, as there is no common ground.
After some Googling, I found that a Windows Runtime Component cannot be used at all times? This seems to be the more flexible choice.
The problem with a Windows Runtime Component is that every public type must be a WinRT type – that means it must be sealed, it can’t inherit from anything (unless it’s something in the Windows.UI.Xaml namespace, such as Control and UserControl). Public fields are not allowed, making declaration of dependency properties a little harder, by forcing a split between a private static field and a public static property.
So something like below is not possible:
public abstract class ObservableObject : INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
var pc = PropertyChanged;
if (pc != null)
pc(this, new PropertyChangedEventArgs(name));
This is classic base class for MVVM support. This does not compile, because an abstract class cannot be exported. We can remove the “public” then this will compile – but will not be exported, so nothing outside this assembly would be able to use it. In a Class Library (Windows Store apps) project, this would compile fine and be usable from other like-assemblies.
What about a plain vanilla Class Library? That is not usable from a Windows Store app, because it uses the full .NET framework, and not just the subset allowed in WinRT. This is exactly what Class Library (Windows Store apps) ensures.
If you’re writing .NET code to be used by other .NET libraries/apps for Windows Store, Class Library (Windows Store apps) is a more flexible choice. If you want the library to be used by any WinRT-compliant language, Windows Runtime Component is your choice.