How to create Silverlight Applications with Notepad

You may have read my post about how you can build Silverlight Web applications with Visual Studio .NET 2005 instead of using the next verison codename Orcas. Until this time I used always a Virtual PC which was sometimes a little bit slow.

Today I was thinking about how I could do this with Notepad. Of course, I will miss the great Intellisense support which you will get with Visual Studio, but sometimes I would like to do small changes i.e. directly on the Web server where I have no Visual Studio installed.

 

What do you need for Silverlight Notepad compile?

First of all you need the Microsoft .NET Framework 2.0, which is a free download available at the Microsoft Download Center. Next we need the DLLs that are referenced by the Silverlight project. They are included in the Silverlight 1.1 Alpha plugin download.

After the installation of both files you will have the C# compiler available in you local Windows folder and the Silverlight files in c:\Program Files\Microsoft Silverlight.

 

My Silverlight build.bat

And now we will build our Silverlight build.bat file which will compile all C# files in a folder into a Silverlight assembly. Let us start with the simple arguments for the C# compiler:

csc.exe /out:SilverlightApp.dll /t:library

The /out argument will name the assembly we get when the compile is finished. The /t will tell the compiler to create a library instead of a executable.

By default the C# compiler will include the standard libraries of the .NET Framework 2. To remove everything I use following arguments:

/nostdlib+ /noconfig

To specifiy the Silverlight core assemblies we will need to add some reference arguments (I set the environment variable %sl% to "c:\Program Files\Microsoft Silverlight"):

/r:"%sl%\agclr.dll"
/r:"%sl%\mscorlib.dll"
/r:"%sl%\system.dll"
/r:"%sl%\System.Core.dll"
/r:"%sl%\System.Silverlight.dll"
/r:"%sl%\System.Xml.Core.dll"

Ok, now we only need the C# source files and, if necessary some resources:

/res:Surface.xaml,SilverlightSurface.Surface.xaml *.cs 

The full build.bat looks like this:

set sl=C:\Program Files\Microsoft Silverlight
set csc=C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe

%csc% /out:SilverlightApp.dll /t:library /nostdlib+ /noconfig 
/r:"%sl%\agclr.dll" /r:"%sl%\mscorlib.dll" /r:"%sl%\system.dll"
/r:"%sl%\System.Core.dll" /r:"%sl%\System.Silverlight.dll"
/r:"%sl%\System.Xml.Core.dll"
/res:Surface.xaml,SilverlightSurface.Surface.xaml *.cs

I have uploaded a ZIP file containing the Silverlight Surface demo source code from my last blog containing a build.bat instead of the solution and project files, you can download it here.

1 Comment

  • I notice in your example you have defined the InitializeComponent function yourself. Why is that?

    As I understand it this is an important function in order to access the child components.

    Why do you define it yourself?
    When I just try to call it in VS2005 I get :
    The name 'InitializeComponent' does not exist in the current context

    Any ideas on how to get around this. I am wondering whether it might be because Orcas generated projects build with a different .target file

Comments have been disabled for this content.