Export (0) Print
Expand All

How to: Compile at the Command Prompt

Two ways to compile a .NET Compact Framework application at the command prompt include:

  • Using the Microsoft Build Engine (MSBuild).

  • Using batch files.

Both methods use the Visual C# and Visual Basic compilers provided by the .NET Framework SDK.

Compiling by Using MSBuild

To build from the command prompt using MSBuild

  1. Ensure that MSBuild.exe is in your system path.

    MSBuild.exe is located in %systemroot%\Microsoft.NET\Framework\version.

  2. At a command prompt, navigate to the directory where the project file for the .NET Compact Framework application is located. The project file will have an .sln, .vbproj, or .csproj extension.

  3. Type the following command followed by the project file name.

    msbuild.exe projectname
    

    The Command Prompt window provides information about the build process.

Compiling by Using Batch Files

You can use batch files to target the .NET Compact Framework assemblies instead of the full .NET Framework (desktop) assemblies. Batch files can be used directly or can be invoked from a make file utility to allow integration of the .NET Compact Framework into enterprise build systems.

The batch file includes the following information:

  • A path variable to the location of the .NET Compact Framework assemblies. The example that follows uses NETCF_PATH.

    NoteNote

    Alternatively, you can specify this path in a make file or as an environment variable using the My Computer properties dialog box.

  • References to assemblies as required, using the -r switch, concatenated into a variable.

  • Compiler commands with the required switches and arguments. The arguments include variable references and an asterisk (*) to incorporate additional arguments.

To create a batch file for compilation

  1. Create a new file in a text editor and add the contents of the sample batch file, as shown in the following example, for your preferred programming language.

  2. Adjust the NETCF_PATH variable, if necessary.

    The .NET Compact Framework assemblies are located by default in the C:\Program Files\Microsoft.NET\SDK\v2.0\CompactFramework\WindowsCE folder.

    NoteNote

    If you are using the SDK included with Visual Studio 2005, the assemblies are in C:\Program Files\Visual Studio version\SmartDevices\SDK\CompactFramework\2.0\v2.0\WindowsCE.

  3. Save and name the file, such as vbcc.bat for a Visual Basic batch file or cscc.bat for a C# batch file.

To compile an application using a batch file

  1. Ensure that your system path includes the .NET Framework.

    The Visual Basic compiler (vbc.exe) and Visual C# compiler (csc.exe) are located in the %systemroot%\Microsoft.NET\Framework\version folder. The system path variable must include this path.

  2. At a command prompt, enter the name of the batch file followed by the source file; for example:

    vbcc myapp.vb
    

    The source file must have a .cs or .vb extension, depending on which compiler will be used.

The executable file, which can be copied to the device or emulator, is built in the current directory.

Batch File for C# Compilation

The following is a sample batch file for C# compilation.

@echo off

if "%NETCF_PATH%" == "" (
  set NETCF_PATH=c:\Program Files\Microsoft.NET\SDK\v2.0\CompactFramework\WindowsCE)

if DEFINED REF ( set REF= )

set REF=%REF% "/r:%NETCF_PATH%\MsCorlib.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Data.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Drawing.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Messaging.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Net.IrDA.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Web.Services.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Windows.Forms.DataGrid.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Windows.Forms.dll"
set REF=%REF% "/r:%NETCF_PATH%\Microsoft.WindowsCE.Forms.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Xml.dll"

csc -nostdlib -noconfig %REF% %*

Batch File for Visual Basic Compilation

The following is a sample batch file for Visual Basic compilation.

@echo off

rem Verify the path is correct.
set NETCF_PATH= c:\Program Files\Microsoft.NET\SDK\v2.0\CompactFramework\WindowsCE
set SDK_PATH="%NETCF_PATH%"

if DEFINED REF ( set REF= )

set REF=%REF% "/r:%NETCF_PATH%\System.Data.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Drawing.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Messaging.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Net.IrDA.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Web.Services.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Windows.Forms.DataGrid.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Windows.Forms.dll"
set REF=%REF% "/r:%NETCF_PATH%\Microsoft.WindowsCE.Forms.dll"
set REF=%REF% "/r:%NETCF_PATH%\System.Xml.dll"
set REF=%REF% "/r:%NETCF_PATH%\Microsoft.VisualBasic.dll"

set IMP= /Imports:Microsoft.VisualBasic,System,System.Data,System.Drawing,System.Windows.Forms

vbc -sdkpath:%SDK_PATH% -netcf -noconfig -nostdlib %IMP% %REF% %* 

Compiler Switches

The following table describes the compiler switches and arguments.

Requirement Description

-r

References assemblies as required.

You can specify assemblies by setting an environment variable, such as REF. Most .NET Compact Framework assemblies are referenced by default.

C# requires an explicit reference to Mscorlib.dll, and Visual Basic uses the -sdkpath switch to locate it.

-imports

Visual Basic requires explicit imports for the following namespaces:

  • Microsoft.VisualBasic

  • System.System.Data

  • System.Drawing

  • System.Windows.Forms

-nostdlb

Instructs the Visual C# compiler to ignore the assemblies of the full (desktop) .NET Framework.

-netcf

Instructs the Visual Basic compiler to ignore the assemblies of the full (desktop) .NET Framework.

-noconfig

Required.

-sdkpath

Required for Visual Basic to locate Mscorlib.dll.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft