Skip to content

Commit 03e2d8f

Browse files
committed
fixed #9 在VisualStudio中调试时,如果启用了VS宿主进程,则版本号识别会有问题
1 parent 06dd1db commit 03e2d8f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

SimpleUpdater/FSLib.App.SimpleUpdater/Defination/UpdateContext.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Diagnostics;
6+
using System.IO;
67
using System.Net;
78
using System.Net.Cache;
89
using System.Reflection;
@@ -21,11 +22,8 @@ public class UpdateContext
2122

2223
public UpdateContext()
2324
{
24-
//CurrentVersion = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).FileVersion);
25-
var processModule = Process.GetCurrentProcess().MainModule;
25+
InitializeCurrentVersion();
2626

27-
CurrentVersion = new Version(processModule.FileVersionInfo.FileVersion);
28-
ApplicationDirectory = System.IO.Path.GetDirectoryName(processModule.FileName);
2927
AutoEndProcessesWithinAppDir = true;
3028
ExternalProcessID = new List<int>();
3129
ExternalProcessName = new List<string>();
@@ -68,6 +66,26 @@ public UpdateContext()
6866
AppendRandomTagInDownloadUrl = true;
6967
}
7068

69+
/// <summary>
70+
/// 初始化当前的版本信息
71+
/// </summary>
72+
void InitializeCurrentVersion()
73+
{
74+
var assembly = Assembly.GetEntryAssembly();
75+
if (assembly != null)
76+
{
77+
CurrentVersion = new Version(FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion);
78+
ApplicationDirectory = Path.GetDirectoryName(assembly.Location);
79+
}
80+
else
81+
{
82+
var processModule = Process.GetCurrentProcess().MainModule;
83+
84+
CurrentVersion = new Version(processModule.FileVersionInfo.FileVersion);
85+
ApplicationDirectory = System.IO.Path.GetDirectoryName(processModule.FileName);
86+
}
87+
}
88+
7189
/// <summary>
7290
/// 尝试从程序集中获得升级属性
7391
/// </summary>

0 commit comments

Comments
 (0)