- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Scala on Microsoft .NET
Created by admin on 2008-07-15.
Updated: 2008-07-28, 11:47
This is a guide on using Scala version 1.4 on the Microsoft .NET platform.
Requirements
Apart from the Scala software distribution you need to install the following software:
- Microsoft .NET Framework Redistributable Package Version 1.0 (or newer) It includes everything you need to run applications built using the .NET Framework, including the Common Language Runtime and class libraries.
Configuration
Then you need to modify your working environment as follows:
- Copy the file mscorlib.dll from the Microsoft .NET directory to the
share\scala\libdirectory of the Scala installation directory. The Scala compiler will need it (see usage of the option-rin the example below) to access the metadata of the Microsoft .NET runtime library.C:\temp>copy %CLR_HOME%\mscorlib.dll %SCALA_HOME%\share\scala\lib
NB. For convenience we assume here that the environment variableCLR_HOMEis defined as follows:Name: CLR_HOME Value: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
- You may now set up your environment in two different ways in order to run the .NET executables generated by the Scala compiler:
- If you have administrator privileges, than register the assembly file
%SCALA_HOME%\lib\scala.dllinto the Global Assembly Cache.Hint: You will find the .NET configuration tool starting from the Start menu of the Windows taskbar and following the steps below:- Control Panel → Administrative Tools → Microsoft .NET Framework Configuration
- In the "Assembly Cache" settings, we then choose the task "Add an Assembly to the Assembly Cache" and select the
scala.dllfile from the Scala installation directory.
- Otherwise you will need to copy the file
%SCALA_HOME%\share\scala\lib\scala.dllin the same directory as the executable.
- If you have administrator privileges, than register the assembly file
Test Example
As our first example, we use the standard Hello World program.
import System.Console object test extends Application { Console.WriteLine("Hello world!") }
To compile the example, we use the Scala compiler with the following two options:
C:\temp>scalac -target:msil -r "%SCALA_HOME%"\share\scala\lib test.scala
and we give the generated assembly file test.il as input to the IL Assembler:
C:\temp>ilasm /output=test.exe /quiet test.il
NB. For using the IL Assembler you may need to modify the environment variable
PATH as follows:Name: PATH Value: ...;%CLR_HOME%\;...
Finally, to run the example, we enter the following command:
C:\temp>test
and get the following output:
Hello world!
Additional Information
Once you've compiled your first Scala program for .NET you may want to dig into more details on the quirks of Scala for .NET, or how .NET specific features map to Scala.




