WinRT Apps : Slow Compilation when you add WinRT components : Solution

PROBLEM

When you create a Blank WinRT project (W8 or WP8.1) with Visual Studio, if you compile as it, it takes : 2 seconds => great !

BUT, if you just add a simple WinRT component library (winmd) as reference and build, it takes 12 to 15 seconds… => wt….???! (if you add a DLL, there is no problem)

Well, it’s not a good start for a project, I didn’t find anything on the Internet about this issue, but I’m sure some developers will burn their computer if they have this issue (maybe they already bought a new CPU 😉 ?)

WHY ?

If you verbose the MSBuild log, you can see this line

> 10179 ms GenerateAppxManifest 1 calls

Ok GenerateAppXManifest is the CPU eater ! We have to found the solution…

SOLUTION

The Solution I found is to override the value AppxHarvestWinmdRegistration to false for MSBUILD in your App csproj, and to fill your AppxManifest .xml Extensions section as it was generated before in the Debug/Release directory – before this hack 🙂 -.

1. open your project.csproj, and add :

<PropertyGroup>   <AppxHarvestWinmdRegistration >false</AppxHarvestWinmdRegistration> </PropertyGroup> <Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />

2. Then, you have to update your AppxManifest.xml like it was before in the Debug/Release dir for the Extensions section (specially if you use the Background Audio or anything which communicate with the external process) :

<Package....

<Extensions>
 <Extension Category="windows.activatableClass.inProcessServer">
 <InProcessServer>
 <Path>CLRHost.dll</Path>
 <ActivatableClass ActivatableClassId="BackgroundAudioTask.MyBackgroundAudioTask" ThreadingModel="both" />
 </InProcessServer>
 </Extension>
 </Extensions>

Have a nice coding day ! 

@poppyto

This entry was posted in Windows Phone 8, WinRT. Bookmark the permalink.