첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

[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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요