Updated: Added missing code snippets.
Hey, I’m excited! I hope you are too. I’ve cracked the code for building C# apps directly with the OS build. That is, as an OS Subproject of a Windows Embedded Compact OS project the Managed Code project can be built and run as with Native Code apps. No SDK needed! No second instance of Visual Studio. There are actually a few ways for doing this but shouldn't we be able to do it like native code subprojects.
The .NET Compact Framework is essentially a subset of the Managed Code classes and APIs with respect to the full framework available for the desktop and above. Originally it also contained same features specific to embedded devices such as the SQL Server CE database classes which morphed into Compact SQL. This is now “owned” by the desktop and not available in the current version of (3.9) of the Compact Framework, as available with Windows Embedded Compact 2013. Another set of classes specific to embedded devices, which only made sense with them, provided the IrDA Infrared API. Earlier versions of CE made much of use of Infrared for device to device communication whereas desktop devices did not. The Infrared APIs were also dropped from the CF in version 3.9 and so the Compact Framework V3.9 is truly just a subset of the desktop Framework. (It seems though that the Compact Framework may never break through to version 4 to include such features as async.)
A comparison of the desktop and Compact Framework circa Compact Framework 2.0
With the inclusion of the Compact Framework in Windows CE 4, an ability to build Managed Code with the OS build engine was enabled. (The CF wasn’t actually included until version 4.1) But it was never seriously documented. You were encouraged to develop and build Managed Code apps in a separate instance of Visual Studio and connect to the target device using Corecon. .. Wasn’t Corecon flaky then!.. How it has improved. Windows CE 4 was actually named Windows CE.NET but it never really lived up to that title.
Whilst not the focus of this article, it would be remiss to not at least provide a summary, for comparison, of using Corecon for developing CF applications on an embedded device. Corecon (core connectivity) is the connectivity transport between the application development system and the target embedded device when the Windows CE/Compact OS of the device is under development suing Platform Builder. The key steps are:
Our book, discusses this in detail for Compact 7.
SDK application development is discussed in detail (in a proposed ebook on embedded101.com) for Compact 2013:
You can create Native Code apps and modules as Subprojects of the OS using the “Add New Subproject” wizard. Why can’t that wizard also generate Managed Code OS Subprojects? Note though that if you right-click on an OS Subproject and choose properties you do get a Managed Code tab. Surely … ????
Managed Code Tab on OS Subproject property sheets
There are only a couple of web pages that discuss this feature circa CE 5 (and reprinted for CE 6). There is no detailed discussion of using this tab. The suggestion is that it’s only for building OS Managed Code components
So the issue is: How do you create and build Managed Code apps as part of the OS build?
There is a solution of sorts with Windows Embedded Compact 7 as discussed in chapter 45 of our book,Professional Windows Embedded Compact 7 (Phung, Jones and Joubert, Wrox Press) . Firstly, armed with a suitable SDK you could add a Smart Device Managed Code project to the OS project’s solution (not in the OS project). You can then add it directly as as OS Subproject (Add-Existing-Subproject). Note that the Smartdevice project is in the root of the OS project, not where the Subprojects are. It will then pop up a message saying:
The following is automatically inserted into to the (now) subproject's .csproj file at the bottom
Hey presto, your Managed Code app now builds directly with the OS! This last action worked with WEC7 because it implemented a unified build. In previous CE versions of the OS, the OS build engine was different to the Subproject build engine. These became the same, MSBuild, with WEC7.But alas with the C++ compiler update in WEC2013, this undocumented feature is now broken! Great while it lasted. Back to the drawing board.
Another approach is again to include the Compact Framework project in the OS solution. You create a content only OS Subproject that consumes the Managed Code build output, as generated by CEComponentWiz. With the CF project configured to be built before the OS, you build the solution. The subproject’s postlink.bat will be configured to copy the CF project’s output to the OS release directory and to include it via a BIB file entry.
Postlink.bat is generated by CEComponentWiz
A tighter approach, is to action the build of the CF subproject by some calls in the subproject’s prelink.bat. You need to separately create the Managed Code project as an SDK project then refer to it in the batch file. Prelink.bat jumps to the project's directory, sets up the Managed Code build environment, then builds the project. Postlink.bat can then get it.
Prelink.bat: Calls MSBuild environment then builds the project
But what if you wanted to just directly create a Managed Code app by Platform Builder? Let’s say a simple .Net Console or Forms app that makes uses of a .NET class for which you know the correct API syntax? That’s what WECSharpWiz on Codeplex is for.
 Another point is why isn’t that wizard extensible?