Monday, March 2, 2009

How to create PE files for .NET Micro Framework without Visual Studio?

While I was searching for a solution to deploy an .NET MF application without Visual Studio I tried the first steps to build my application with the .NET Framework compiler from command line.

I downloaded the .NET MF Framework SDK 2.5 and installed it on a Virtual PC. This download includes all the DLLs including the core library for .NET MF. The compiler itself comes with the standard .NET Framework 2.0.

For testing purpose I created a new .NET MF project and copied Program.cs and GPIOButtonInputProvider.cs in a temporary folder. Next I created following batch file which will compile and start the .NET MF Emulator:

SET NET_BIN=%windir%\Microsoft.NET\Framework\v2.0.50727

SET MF_VER=v2.0.3036
REM SET MF_VER=v3.0

SET MF_BIN=%programfiles%\Microsoft .NET Micro Framework\%MF_VER%\Tools
SET MF_LIB=%programfiles%\Microsoft .NET Micro Framework\%MF_VER%\Assemblies

"%NET_BIN%\csc.exe" /noconfig /nostdlib+ /optimize- /r:"%MF_LIB%\mscorlib.dll" /r:"%MF_LIB%\Microsoft.SPOT.Native.dll" /r:"%MF_LIB%\Microsoft.SPOT.Graphics.dll" /r:"%MF_LIB%\Microsoft.SPOT.Hardware.dll" /r:"%MF_LIB%\Microsoft.SPOT.TinyCore.dll" /out:Program.exe /target:exe *.cs

"%MF_BIN%\MetaDataProcessor.exe" -loadHints mscorlib "%MF_LIB%\mscorlib.dll"
-loadHints Microsoft.SPOT.Native "%MF_LIB%\Microsoft.SPOT.Native.dll"
-loadHints Microsoft.SPOT.Graphics "%MF_LIB%\Microsoft.SPOT.Graphics.dll"
-loadHints Microsoft.SPOT.Hardware "%MF_LIB%\Microsoft.SPOT.Hardware.dll"
-loadHints Microsoft.SPOT.TinyCore "%MF_LIB%\Microsoft.SPOT.TinyCore.dll"
-parse Program.exe -minimize
-compile HelloWorld.pe

"%MF_BIN%/Microsoft.SPOT.Emulator.Sample.SampleEmulator.exe"
/load:HelloWorld.pe /load:"%MF_LIB%\mscorlib.pe" /load:"%MF_LIB%\Microsoft.SPOT.Native.pe" /load:"%MF_LIB%\Microsoft.SPOT.Graphics.pe" /load:"%MF_LIB%\Microsoft.SPOT.Hardware.pe" /load:"%MF_LIB%\Microsoft.SPOT.TinyCore.pe"

Well, I found a solution to build my .NET MF projects and got my DLL and PE files. The only missing part is deploying the files to a real device which is not working outside of Visual Studio.

No comments: