[C#] 현재 Application Version 얻기

2014. 10. 31. 16:56Coders

버전 관리를 하면서 윈폼 등으로 프로그램을 작성할 때, 현재 프로그램의 버전이 궁금하거나, 화면상에 표시해야 할 때가 있습니다. 간단한 코드로 현재 어플리케이션의 버전을 확인할 수 있습니다.


배포용의 Version 클래스 얻기를 시도하고 실패했을 때에는 현재 어셈블리의 버전을 리턴합니다.


public static string GetAppVer()
{
	try
	{
		//게시(Clickonce 등 일 경우) 응용프로그램 버전
		return string.Format("{0} (배포버전)",
			System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion);
	}
	catch
	{
		//로컬 빌드 버전일 경우 (현재 어셈블리 버전)
		return string.Format("{0} (빌드버전)",
			System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
	}
}