Questa classe rinominerà l'eseguibile attualmente in esecuzione, se si completa senza eccezione, si può semplicemente scrivere il nuovo eseguibile, quindi rilanciare, ad esempio: abbastanza
Ourself.Rename();
// Download or copy new version
File.Copy(newVersion, Ourself.FileName());
// Launch new version
System.Diagnostics.Process.Start(Ourself.FileName());
// Close current version
Close(); // Exit();
facile?
class Ourself
{
public static string FileName() {
Assembly _objParentAssembly;
if (Assembly.GetEntryAssembly() == null)
_objParentAssembly = Assembly.GetCallingAssembly();
else
_objParentAssembly = Assembly.GetEntryAssembly();
if (_objParentAssembly.CodeBase.StartsWith("http://"))
throw new IOException("Deployed from URL");
if (File.Exists(_objParentAssembly.Location))
return _objParentAssembly.Location;
if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + System.AppDomain.CurrentDomain.FriendlyName))
return System.AppDomain.CurrentDomain.BaseDirectory + System.AppDomain.CurrentDomain.FriendlyName;
if (File.Exists(Assembly.GetExecutingAssembly().Location))
return Assembly.GetExecutingAssembly().Location;
throw new IOException("Assembly not found");
}
public static bool Rename()
{
string currentName = FileName();
string newName = FileName() + ".ori";
if (File.Exists(newName))
{
File.Delete(newName);
}
File.Move(currentName, newName);
return true;
}
}
Sembra esserci un progetto su Codeplex che mira alla distribuzione a caldo per .NET. Non ho provato però: http://hotdeploy.codeplex.com/ –