Reducing the Size of .NET Applications

by Vasian Cepa



Listing One



FileStream fs = new FileStream("app.zip", FileMode.Open, FileAccess.Read);

byte[] data = new byte[fs.Length];

fs.Read(data, 0, data.Length);

fs.Close();



ResourceWriter rm = new ResourceWriter("app.resources");

rm.AddResource("app.exe", data);

rm.Close();





Listing Two



public static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)

{

    int i = args.Name.IndexOf(',');

    string dllName = args.Name.Substring(0, i);



    // dllName equals "lib" in the example; mapped to the zipped filename

    dllName += "z.dll";



    // read the file and unzip the data as above code omitted ...

    byte[] uzdata = ...



    return Assembly.Load(uzdata);

}











1



