Skip to content

Commit 7cee518

Browse files
author
Lessley Dennington
committed
assembly: add assemblyutils
The implementation of TRACE2 tracing will require use of the TryGetAssemblyVersion method. To prepare for this, move this method out of the DiagnoseCommand class and into its own static class.
1 parent 66b94e4 commit 7cee518

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/shared/Core/AssemblyUtils.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Reflection;
2+
3+
namespace GitCredentialManager;
4+
5+
public static class AssemblyUtils
6+
{
7+
public static bool TryGetAssemblyVersion(out string version)
8+
{
9+
try
10+
{
11+
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
12+
var assemblyVersionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
13+
version = assemblyVersionAttribute is null
14+
? assembly.GetName().Version.ToString()
15+
: assemblyVersionAttribute.InformationalVersion;
16+
return true;
17+
}
18+
catch
19+
{
20+
version = null;
21+
return false;
22+
}
23+
}
24+
}

src/shared/Core/Commands/DiagnoseCommand.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private async Task<int> ExecuteAsync(string output)
8686
fullLog.WriteLine($"AppPath: {_context.ApplicationPath}");
8787
fullLog.WriteLine($"InstallDir: {_context.InstallationDirectory}");
8888
fullLog.WriteLine(
89-
TryGetAssemblyVersion(out string version)
89+
AssemblyUtils.TryGetAssemblyVersion(out string version)
9090
? $"Version: {version}"
9191
: "Version: [!] Failed to get version information [!]"
9292
);
@@ -198,24 +198,6 @@ private async Task<int> ExecuteAsync(string output)
198198
return numFailed;
199199
}
200200

201-
private bool TryGetAssemblyVersion(out string version)
202-
{
203-
try
204-
{
205-
var assembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
206-
var assemblyVersionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
207-
version = assemblyVersionAttribute is null
208-
? assembly.GetName().Version.ToString()
209-
: assemblyVersionAttribute.InformationalVersion;
210-
return true;
211-
}
212-
catch
213-
{
214-
version = null;
215-
return false;
216-
}
217-
}
218-
219201
private static class ConsoleEx
220202
{
221203
public static void WriteLineIndent(string str)

0 commit comments

Comments
 (0)