This workes perfectly fine when building it inside Visual Studio 2010, but when building it from the command line using MSBuild 4.0 it fails, complaining about not finding the GetDeviceFrameworkPath in the Microsoft.CompactFramework.Build.Tasks. This has to do with an error in the configuration file for MSBuild.
The solution is to edit the msbuild.exe.config file in the [Windows]\Microsoft.NET\Framework\v4.0.21006 folder and to remove the binding redirect for Microsoft.CompactFramework.Build.Tasks to version 10.0.0.0, which does not exist yet.
Lines to remove:
<dependentAssembly>
<assemblyIdentity name="Microsoft.CompactFramework.Build.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="10.0.0.0"/>
</dependentAssembly>

I know that I had configured the apartment state to STA in the NUnit config file corresponding to the NUnit project file (or assembly). TestDriven.NET states that it defaults to run with STA as apartment state, but still it complained about not being STA.
The solution for me was to explicitly add the RequiresSTA attribute to the class being tested. The RequiresSTA attribute can be added to individual test methods, an entire test fixture or the whole assembly.

I found this blog post describing the issue and a workaround that not only is specific for Visual Studio 2010, but for all WPF application.
Simply disable hardware acceleration by creating a registry value HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration, as a DWORD with a value of 1.

Things to change in VS 2008 .NET Compact Framework (Smart Device) projects to make them load and build in VS 2010 while still targeting the .NET Compact Framework.
1) Edit the project file (*.csproj) for your smart device project.
2) Make sure the ToolsVersion attribute is set to 4.0.
3) Remove the ProjectTypeGuids property item from the main property group.
4) Both PlatformFamilyName and PlatformID are important for the project to correctly target the .NET Compact Framework.
5) Change the import item for the Compact Framework build task to specify the location of the Microsoft.CompactFramework.CSharp.targets file. Either hard-code the path in the task or add the path to a property item in the main property group and reference that in the import item.
Example #1:
<Import Condition="'$(TargetFrameworkVersion)' == 'v3.5'" Project="C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets" />
Example #2:
<PropertyGroup>
<MSBuildBinPathCF Condition=" '$(MSBuildBinPathCF)' == '' ">C:\Windows\Microsoft.NET\Framework\v3.5</MSBuildBinPathCF>
</PropertyGroup>
<Import Condition="'$(TargetFrameworkVersion)' == 'v3.5'" Project="$(MSBuildBinPathCF)\Microsoft.CompactFramework.CSharp.targets" />
6) Remove the import tasks for older versions of the .NET Compact Framework or configure them correctly.
7) Copy the "Microsoft.CompactFramework.Common.targets" file from [Windows]\Microsoft.NET\Framework\v3.5 to [Windows]\Microsoft.NET\Framework\v4.0.21006.
8) Reload the project. It might still ask for a conversion but this time it will load the project correctly.
Things to change in VS 2010 project files, targeting .NET 3.5, to make them target the .NET Compact Framework 3.5.
1) Replace the MSBuild project task targeting the .NET Framework to the one targeting the .NET Compact Framework, i.e. Microsoft.CompactFramework.CSharp.targets. Either hard-code the path in the task or add the path to a property item in the main property group and reference that in the import item.
Example #1:
<Import Condition="'$(TargetFrameworkVersion)' == 'v3.5'" Project="C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets" />
Example #2:
<PropertyGroup>
<MSBuildBinPathCF Condition=" '$(MSBuildBinPathCF)' == '' ">C:\Windows\Microsoft.NET\Framework\v3.5</MSBuildBinPathCF>
</PropertyGroup>
<Import Condition="'$(TargetFrameworkVersion)' == 'v3.5'" Project="$(MSBuildBinPathCF)\Microsoft.CompactFramework.CSharp.targets" />
2) Add the following property items to the main property group:
<PlatformFamilyName>WindowsCE</PlatformFamilyName>
<PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID>
3) Copy the "Microsoft.CompactFramework.Common.targets" MSBuild .NET Compact Framework target file, from [Windows]\Microsoft.NET\Framework\v3.5 to [Windows]\Microsoft.NET\Framework\v4.0.21006:
4) Reload the project.
