|
Listing 3-17 extracted from chapter Build, deploy and configure your .NET applications
Listing 3-16< > Listing 3-18
This listing can be compiled with the command line: csc.exe /out:MyApp.exe /target:exe Example_3_17_to_rename_MyApp.cs /r:System.dll /r:MyLib.dll /r:System.Deployment.dll Errors: 0 Warnings: 0
Example_3_17_to_rename_MyApp.cs
using System;
using System.Reflection;
using System.Deployment.Application;
class Program {
public static void Main() {
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler;
Console.WriteLine("Hello from MyApp.");
Foo.FooFct();
}
static Assembly AssemblyResolveHandler(object sender,
ResolveEventArgs args) {
if ( ApplicationDeployment.IsNetworkDeployed ) {
// The 'CurrentDeployement' property returns null
// when the application is not deployed hence the test
// for the property 'IsNetworkDeployed'.
ApplicationDeployment currentDeployment =
ApplicationDeployment.CurrentDeployment;
currentDeployment.DownloadFileGroup("MyGroup");
Console.WriteLine("Downloading...");
}
return Assembly.Load("MyLib");
}
}
class Foo {
public static void FooFct() {
MyClass a = new MyClass();
Console.WriteLine(a);
}
}
Copyright Patrick Smacchia 2006 2007
|