728x90
반응형
728x170
[TestProject 프로젝트]
▶ MainForm.cs
using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
Load += Form_Load;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
string executablePath = Path.GetDirectoryName(Application.ExecutablePath);
string filePath = Path.Combine(executablePath, "SourceProject.exe");
Version version = GetVersion(filePath);
this.versionLabel.Text = "SourceProject.exe : " + version.ToString();
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 버전 구하기 - GetVersion(assemblyFilePath)
/// <summary>
/// 버전 구하기
/// </summary>
/// <param name="assemblyFilePath">어셈블리 파일 경로</param>
/// <returns>버전</returns>
private Version GetVersion(string assemblyFilePath)
{
AppDomain appDomain = AppDomain.CreateDomain("testDomain");
appDomain.SetData("assemblyFilePath", assemblyFilePath);
appDomain.DoCallBack
(
new CrossAppDomainDelegate
(
() => {
string targetAssemblyFilePath = AppDomain.CurrentDomain.GetData("assemblyFilePath") as string;
Assembly targetAssembly = Assembly.LoadFile(targetAssemblyFilePath);
Version targetVersion = targetAssembly.GetName().Version;
AppDomain.CurrentDomain.SetData("targetVersion", targetVersion);
}
)
);
Version version = appDomain.GetData("targetVersion") as Version;
AppDomain.Unload(appDomain);
return version;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] Encoding 클래스 : 대체(fallback) 메커니즘 사용하기 (0) | 2019.07.16 |
---|---|
[C#/COMMON] MemoryStream 클래스 : Encoding 객체의 GetBytes 메소드를 사용해 문자열에서 메모리 스트림 구하기 (0) | 2019.07.14 |
[C#/COMMON] 특정 프로세스에서 오픈한 파일과 핸들 리스트 구하기 (0) | 2019.07.14 |
[C#/COMMON] 관리 DLL 여부 구하기 (0) | 2019.07.13 |
[C#/COMMON] Encoding 클래스 : GetEncodings 정적 메소드를 사용해 문자열 인코딩 리스트 구하기 (0) | 2019.07.13 |
[C#/COMMON] 거리 구하기 (0) | 2019.07.13 |
[C#/COMMON] Char 구조체 : IsNumeric 함수를 사용해 숫자 문자열 여부 구하기 (0) | 2019.07.13 |
[C#/COMMON] 프로젝트에서 x86/x64별로 나누어진 어셈블리 참조하기 (0) | 2019.07.04 |
[C#/COMMON] DataTable 클래스 : Select 메소드에서 DateTime 조건문 사용하기 (0) | 2019.06.30 |
[C#/COMMON] 한글 오토마타 사용하기 (0) | 2019.06.28 |
댓글을 달아 주세요