Thursday, June 14, 2007

Using SharpDevelop as a Portable App

Lately I’ve been messing around with SharpDevelop.  Mainly because I think I’m going to pick Boo as my one new programming language each year.  As part of my research I’ve discovered that it can be used as a Portable App.  That is, it can be run directly from a USB thumb drive without an install.  In it’s simplest form all that is needed is to copy the files from the install directory to the thumb drive and away you go.  However if you are using the PortableApps Suite and want SharpDevelop to show up in you menu it’s a little harder.

 

First the PortableApss Suite expects all its applications to exist in folders that end in “portable”.  This isn’t hard to do just create a ShpapDevelopPortable folder under the PortableApps directory and copy the files there.  Now, the second hurtle is that the Suite menu expects the executable to be in that root folder; SharpDevlop is not, it’s in a bin folder.  You could probably move the assemblies to the root directory but it would probable create problems with some of the resource dependences.  So, I decided to create a proxy exe that would call the real one.  Here is the entire source code.

 

/*

 * Created by SharpDevelop.

 * User: Trevor Michealson

 * Date: 6/13/2007

 * Time: 11:17 PM

 *

 * To change this template use Tools | Options | Coding | Edit Standard Headers.

 */

using System;

using System.Collections.Generic;

using System.Diagnostics;

 

 

namespace SharpDevelop

{

       class MainClass

       {

             

              public static void Main(string[] args)

              {

                        string apploc = @"/bin/SharpDevelop.exe";

                            Process SharpDev = new Process();

 

                if (System.IO.File.Exists(apploc))

                    SharpDev.StartInfo.FileName = apploc;

                else

                    SharpDev.StartInfo.FileName =

                    @"/PortableApps/SharpDevelopPortable/" + apploc;

                SharpDev.Start();

               

              }

       }

}

 

 

The if statement determines if you are running from the menu or if you’ve run the exe directly, it gets a different working directory in both.

 

Note: when I brought it to work it ran in completely different working directory.  I’m not sure if this is Windows 2000 or a profile setting but this code did work on both my Home PC (running XP) and my Laptop(running Server 2003).

2 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...
This comment has been removed by a blog administrator.