The Kinetic Jump site navigation header requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

Welcome Guest Search | Active Topics | Log In | Register

Update Single exe applications Options
brianh
#1 Posted : Thursday, June 28, 2007 11:04:46 AM
Rank: Administration
Groups: Member, Administration

Joined: 5/24/2007
Posts: 362
Location: Minnesota
You can embed the Update Controller into your exe and use the AppDomain AssemblyResolve event to extract the controller during updating activity.

To do this, add the Update Controller assembly (Kjs.AppLife.Update.Controller.dll) to your Visual Studio project and from it's properties grid, set the Build Action to Embedded Resource.

In the application entry point (usually Program.Main), add an event handler to extract the Update Controller assembly.

Code:

static void Main() {
  AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
  ...
}

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs e) {
  if(e.Name.StartsWith("Kjs.AppLife.Update.Controller", StringComparison.Ordinal)) {
    using(Stream inputStream = typeof(Program).Assembly.GetManifestResourceStream("YOURASSEMBLYNAME.Kjs.AppLife.Update.Controller.dll")) {
      using(BinaryReader reader = new BinaryReader(inputStream)) {
        return Assembly.Load(reader.ReadBytes((int)inputStream.Length));
        }
      }
    }

    return null;
}


Code:
Imports System.IO
Imports System.Reflection

Public Class Form1
  Private WithEvents mAppDomain As AppDomain = AppDomain.CurrentDomain
  ...

  Private Function mAppDomain_AssemblyResolve(ByVal sender As Object, ByVal args As System.ResolveEventArgs) As System.Reflection.Assembly Handles mAppDomain.AssemblyResolve
    If args.Name.StartsWith("Kjs.AppLife.Update.Controller", StringComparison.Ordinal) Then
      Using inputStream As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Simple.Kjs.AppLife.Update.Controller.dll")
        Using reader As BinaryReader = New BinaryReader(inputStream)
          Return Assembly.Load(reader.ReadBytes(CType(inputStream.Length, Int32)))
        End Using
      End Using
    End If
    Return Nothing
  End Function
End Class


After this step, you can distribute a single executable that is update enabled.
Brian Haas
Kinetic Jump Software
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.