Skip to content

Commit

Permalink
fixed #9 在VisualStudio中调试时,如果启用了VS宿主进程,则版本号识别会有问题
Browse files Browse the repository at this point in the history
  • Loading branch information
iccfish committed Mar 4, 2016
1 parent 06dd1db commit 03e2d8f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions SimpleUpdater/FSLib.App.SimpleUpdater/Defination/UpdateContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Cache;
using System.Reflection;
Expand All @@ -21,11 +22,8 @@ public class UpdateContext

public UpdateContext()
{
//CurrentVersion = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).FileVersion);
var processModule = Process.GetCurrentProcess().MainModule;
InitializeCurrentVersion();

CurrentVersion = new Version(processModule.FileVersionInfo.FileVersion);
ApplicationDirectory = System.IO.Path.GetDirectoryName(processModule.FileName);
AutoEndProcessesWithinAppDir = true;
ExternalProcessID = new List<int>();
ExternalProcessName = new List<string>();
Expand Down Expand Up @@ -68,6 +66,26 @@ public UpdateContext()
AppendRandomTagInDownloadUrl = true;
}

/// <summary>
/// 初始化当前的版本信息
/// </summary>
void InitializeCurrentVersion()
{
var assembly = Assembly.GetEntryAssembly();
if (assembly != null)
{
CurrentVersion = new Version(FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion);
ApplicationDirectory = Path.GetDirectoryName(assembly.Location);
}
else
{
var processModule = Process.GetCurrentProcess().MainModule;

CurrentVersion = new Version(processModule.FileVersionInfo.FileVersion);
ApplicationDirectory = System.IO.Path.GetDirectoryName(processModule.FileName);
}
}

/// <summary>
/// 尝试从程序集中获得升级属性
/// </summary>
Expand Down

0 comments on commit 03e2d8f

Please sign in to comment.