Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build .NET Compact Framework 3.5

Install

Force MSBuild support

  • Copy files and directories from 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\*' to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5';
  • Copy files from 'C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\Debugger\BCL\*' to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework' directory;
  • Create 'RedistList' directory inside created 'CompactFramework' directory;
  • Create 'FrameworkList.xml' inside 'RedistList' directory and type the following:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\RedistList\FrameworkList.xml

<?xml version="1.0" encoding="utf-8"?>
<FileList  Redist="Net35-CF" Name=".NET Compact Framework 3.5">
</FileList>

Visual Studio 2017/2019 - .NET Standard/Class Library

If do not care to add a dependency to the project to support 'net35-cf' build, configure the project as follows:

project.csproj

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;net35-cf</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NETStandard.WindowsCE" Version="1.4.0" />
  </ItemGroup>

Otherwise, if do not want to use any support package. You must to configure the project as follows:

project.csproj

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;net35-cf</TargetFrameworks>
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'net35-cf'">
    <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <TargetFrameworkProfile>CompactFramework</TargetFrameworkProfile>
    <DefineConstants>$(DefineConstants);NET35_CF;WindowsCE</DefineConstants>
    <DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences>
    <NoStdLib>True</NoStdLib>
    <NoConfig>true</NoConfig>
    <FileAlignment>512</FileAlignment>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID>
    <Optimize>False</Optimize>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'net35-cf'">
    <Reference Include="mscorlib, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System.Data, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System.Runtime.Serialization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System.Xml, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
  </ItemGroup>

Visual Studio 2015 - Core XPROJ

  • Use 'net35-cf' or '.NETFramework,Version=v3.5,Profile=CompactFramework' TFM.

project.json

{
    "frameworks": {
        "net35-cf": {
            "frameworkAssemblies": {
                "mscorlib": "",
                "System": "",
                "System.Core": ""
            }
        }
    }
}

Visual Studio 2015 - Classic CSPROJ

PropertyGroup

    <NoStdLib>True</NoStdLib>
    <NoConfig>true</NoConfig>
    <FileAlignment>512</FileAlignment>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID>

ItemGroup

    <Reference Include="mscorlib, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />

Project

  <Import Project="$(SolutionDir)Microsoft.CompactFramework.CSharp.targets" />

Use deprecated MSBuild 3.5

  • Path: C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
  • On 'C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets' file replace '$(MSBuildBinPath)' by 'C:\Windows\Microsoft.NET\Framework\v3.5'.
  • On .CSPROJ file, replace '$(MSBuildBinPath)' by 'C:\Windows\Microsoft.NET\Framework\v3.5'.
@joelharkes

This comment has been minimized.

Copy link

joelharkes commented Sep 12, 2017

Awesome seriously many thanks! 🥇

good to know is that RedistList\FrameworkList.xml
means is that you add this folder and file to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework

Im working on getting it to work in vs2017 now, im not sure what the 'Core' subject means what i'd need to change here.

@ashalkhakov

This comment has been minimized.

Copy link

ashalkhakov commented Sep 27, 2017

In a .NET Core csproj file:

  1. replace the TargetFramework property with <TargetFrameworks>netstandard2.0;net35-cf</TargetFrameworks> (where netstandard2.0 stands for whatever was specified in the property)
  2. then add the following conditional elements:
	<PropertyGroup Condition="'$(TargetFramework)' == 'net35-cf'">
                <!-- inference fails for this TFM, so specify it by hand -->
		<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
		<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
		<TargetFrameworkProfile>CompactFramework</TargetFrameworkProfile>
                <!-- define compilation constants by hand too -->
		<DefineConstants>NET35_CF;WindowsCE</DefineConstants>
                <!-- disable implicit references, these are specified by hand, below -->
		<DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences>
	</PropertyGroup>
	<PropertyGroup Condition=" '$(TargetFramework)' == 'net35-cf' ">
		<NoStdLib>True</NoStdLib>
		<NoConfig>true</NoConfig>
		<FileAlignment>512</FileAlignment>
		<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
		<PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID>
	</PropertyGroup>
	<ItemGroup Condition=" '$(TargetFramework)' == 'net35-cf' ">
		<Reference Include="mscorlib, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
		<Reference Include="System, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
		<Reference Include="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
	</ItemGroup>

This works for me on VS 2017. The resulting assembly can indeed be deployed to a WinMo6.5 Professional device, yay! I also had to add the following directory to the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v3.5,Profile=CompactFramework following this helpful post

@feO2x

This comment has been minimized.

Copy link

feO2x commented Mar 4, 2018

I tried the steps above, but unfortunately I get an error with the AssemblyFileVersionAttribute that is generated for the .NET 3.5 CF assembly:

image

@skarllot, @ashalkhakov, did you face something similar? Have I missed a step? I've done the following:

  • Installed .NET CF 3.5 and Power Toys
  • Replaced '$(MSBuildBinPath)' with 'C:\Windows\Microsoft.NET\Framework\v3.5'
  • Everything described in Use latest MSBuild
  • Added registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v3.5,Profile=CompactFramework
  • Created new project, set target frameworks and added conditional property groups for net35-cf

Everything compiles fine when I remove the net35-cf framework moniker. I'm currently using VS 15.5.7 with msbuild 15.5.180.51428.

@feO2x

This comment has been minimized.

Copy link

feO2x commented Mar 5, 2018

In the end, I just had to add the following XML to the second conditional property group for net35-cf:

<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>

Multitargeting worked fine after that and I could succesfully call the resulting DLL in a WinCE Forms application.

@ashalkhakov

This comment has been minimized.

Copy link

ashalkhakov commented Mar 15, 2018

@feO2x glad you fixed it! I missed the notification, sorry.

Just came here because I'm trying to build a Docker image for automating CF builds. If we could also use Linux for that (with .NET Core), that would be even better!

EDIT: I'll try it with Rider (on Linux and Windows). If anything of value comes up, will report it here.

@feO2x

This comment has been minimized.

Copy link

feO2x commented Mar 16, 2018

@ashalkhakov Sounds great. I also stumbled upon MSBuildSdkExtras which adds a lot more TFMs that can be used as target frameworks. I've added an issue for supporting NET-CF 3.5 as well, based on this gist.

@ashalkhakov

This comment has been minimized.

Copy link

ashalkhakov commented Mar 19, 2018

I came up with the following solution.

This at least saves you the trouble of manually installing deps off MS website. We push this build env image to our Docker Registry, and the use it for running CF-specific builds as usual. Maybe we can also tackle the second approach (compiling with modern MSBuild), that's just a few steps away.

@joelharkes

This comment has been minimized.

Copy link

joelharkes commented Oct 2, 2018

Copying:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\*
to 
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5

actually broke it, i had to clear the whole folder and copy paste a copy from someone else back in there to make my normal net35 builds work again.

problem <TargetFrameworks>net35</TargetFrameworks> no longer builds if you this above.

Is there any way around this problem?

@joelharkes

This comment has been minimized.

Copy link

joelharkes commented Oct 2, 2018

Got it to work without copying step see above.

but i had to hard set reference to dll's because they are now not found, like such:

    <Reference Include="System.Windows.Forms">
    <HintPath>C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\System.Windows.Forms.dll</HintPath>
    </Reference>

i tried setting AssemblySearchPaths but that wouldnt work somehow:

 <AssemblySearchPaths>$(AssemblySearchPaths);{GAC};C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\</AssemblySearchPaths> 

i can build now:

<TargetFrameworks>net35;net35-cf;net452</TargetFrameworks>
@joelharkes

This comment has been minimized.

Copy link

joelharkes commented Oct 2, 2018

Finally got it to work with:

<AssemblySearchPaths>$(AssemblySearchPaths);C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE;</AssemblySearchPaths>

instead of the hint paths.

@joelharkes

This comment has been minimized.

Copy link

joelharkes commented Oct 9, 2018

Here simple bat file (run as admin)

@echo off
::@setlocal enableextensions enabledelayedexpansion
pushd "%~dp0"

if not exist "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\" (
  mkdir "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\"
)
::this actualy breaks net35 builds so we disable this!
::xcopy "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\*" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\"
if not exist "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\" (
  mkdir "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\"
)

if not exist "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\" (
  mkdir "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\"
)
xcopy "C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\Debugger\BCL\*" "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\" /S /Y

if not exist "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\RedistList\" (
  mkdir "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\RedistList\"
)

if not exist "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\RedistList\FrameworkList.xml" (
  ( 
    echo ^<?xml version="1.0" encoding="utf-8"?^>
    echo ^<FileList Redist="Net35-CF" Name=".NET Compact Framework 3.5"^>
    echo ^</FileList^>
  )  > "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework\RedistList\FrameworkList.xml"
)
popd
@easysoft2k15

This comment has been minimized.

Copy link

easysoft2k15 commented Jun 20, 2019

Hello,
using the instructions reported I was able to compile a simple project with a win form and make it run in a Windows Compact 7 Device.
Is there a way to have designer support for Windows Form using Visual Studio 2017?
When I try to open the form with the designer I get an Exception:

Value cannot be null. Parameter name: instance

I'm using this .csproj:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup> <TargetFrameworks>net35-cf</TargetFrameworks> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <ApplicationIcon /> <OutputType>WinExe</OutputType> <StartupObject /> </PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net35-cf'"> <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkProfile>CompactFramework</TargetFrameworkProfile> <DefineConstants>$(DefineConstants);NET35_CF;WindowsCE</DefineConstants> <DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences> <NoStdLib>True</NoStdLib> <NoConfig>true</NoConfig> <FileAlignment>512</FileAlignment> <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> <PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID> <Optimize>False</Optimize> </PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net35-cf'"> <Reference Include="mscorlib, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" /> <Reference Include="System, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" /> <Reference Include="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" /> <Reference Include="System.Data, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" /> <Reference Include="System.Runtime.Serialization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" /> <Reference Include="System.Xml, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" /> <Reference Include="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" /> <Reference Include="System.Windows.Forms"> <HintPath>C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\System.Windows.Forms.dll</HintPath> </Reference> <Reference Include="System.Drawing"> <HintPath>C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\System.Drawing.dll</HintPath> </Reference> </ItemGroup>

<ItemGroup> <Compile Update="Form1.cs"> <SubType>Form</SubType> </Compile> <Compile Update="Form1.Designer.cs"> <DependentUpon>Form1.cs</DependentUpon> </Compile> </ItemGroup> </Project>

@skarllot

This comment has been minimized.

Copy link
Owner Author

skarllot commented Jun 20, 2019

@easysoft2k15 I've never achieved designer support on VS.

This can change in future with VS2019, because it supports Windows Forms on Core project.

Ref: https://docs.microsoft.com/en-us/dotnet/core/porting/winforms

@easysoft2k15

This comment has been minimized.

Copy link

easysoft2k15 commented Jun 21, 2019

@skarllot Thank You for Your feedback.
I'll give it i try and if come up with something I'll report it here.

@pentestdude

This comment has been minimized.

Copy link

pentestdude commented Nov 14, 2019

Is this supposed to work on VS2019 as well?

@skarllot

This comment has been minimized.

Copy link
Owner Author

skarllot commented Nov 14, 2019

@pentestdude Yes, it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.