2008-11-27 2 views
23

asp.net 웹 응용 프로그램에 여러 버전의 네트워크가있는 다른 고객 서버에 배포되어 있습니다. 우리가 가진 한 가지 관행은 고객에게 문제가있을 때 이메일로 스크린 샷을 보내도록하는 것입니다.ASP.NET - 화면 맨 아래에 응용 프로그램 빌드 날짜/정보 표시

이전 asp.net에서 1.1 일 동안 리플렉션을 사용하여 빌드 DLL의 세부 사항을 파악하고 빌드 날짜 및 화면의 미묘한 위치에 번호 매기기에 대한 정보를 표시 할 수있었습니다.

.NET 2.0 이상에서는 빌드 모델이 변경되어 더 이상이 메커니즘이 작동하지 않습니다. 거기에 다른 빌드 시스템에 대해 들었지만 3.5 프레임 워크에서이 기능이 프레임 워크 1.1에서 한 일을하는 가장 간단한 방법을 찾고 있습니다.

  1. 빌드가 수행 될 때마다,
  2. 이 간단 할 화면에 표시, 빌드 타임 스탬프 및 번호를 볼 수 빌드 번호
  3. 을 빌드 날짜/시간을 업데이트하고, 어떻게 든 업데이트 가능한 구현하는 것은
+0

는 http://stackoverflow.com/questions/1168279/asp-net-version-build-number/1168329#1168329 – Saber

답변

17

우리는 닷넷 2.0을 사용하여 어셈블리에서 버전 정보를 끌어 있습니다. 아마도 이상적이지는 않지만 설명을 사용하여 빌드 날짜를 저장합니다.

Assembly assembly = Assembly.GetExecutingAssembly(); 
string version = assembly.GetName().Version.ToString(); 
string buildDate = ((AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
    assembly, typeof(AssemblyDescriptionAttribute))).Description; 

빌드 프로세스는 asminfo nant 태스크를 사용하여이 정보가 들어있는 AssemblyInfo.cs 파일을 생성합니다.

<asminfo output="Properties\AssemblyInfo.cs" language="CSharp"> 
     <imports> 
      <import namespace="System" /> 
      <import namespace="System.Reflection" /> 
      <import namespace="System.Runtime.CompilerServices" /> 
      <import namespace="System.Runtime.InteropServices" /> 
     </imports> 
     <attributes> 
      <attribute type="AssemblyVersionAttribute" value="${assembly.version}" /> 
      <attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version}" /> 
      <attribute type="AssemblyDescriptionAttribute" value="${datetime::now()}" /> 
      ... 
     </attributes> 
    </asminfo> 
+0

정확히 내가 찾던 해결책의 유형입니다. 좋은 양식. – pearcewg

+1

나는 이것과 매우 비슷한 코드를 가지고 있는데, 사용자 정의 컨트롤에 끌어다 놓기 만하면된다. :) –

7

이 예, 반사를 통해 어셈블리 빌드 날짜를 얻을 확인할 수 있습니다

+1

"날짜 어려운 방법을 구축 결정하는 것은"나를 위해 작동합니다. – zsong

+0

Coding Horror 솔루션으로 멋지게 찾을 수 있습니다. - major.minor. * 다음의 어셈블리 버전에 의존하는 기본 솔루션이 마음에 들지 않습니다.0 패턴, 나는 어셈블리 파일을 major.minor.0.0으로, 어셈블리 파일 버전을 major.minor.build.revision으로 설정 했으므로 핫픽스 어셈블리를 쉽게 할 수있다. 링커의 타임 스탬프를 읽는 것은 매우 교활합니다. +1 라운드! –

16

.NET 2.0 및 3.5을 사용하고 있으며 빌드 번호와 빌드 날짜를 모두 설정할 수 있습니다. 도움말 패널에서는 .NET에서 설정 한 경우 개정판에 임의의 숫자를 사용합니다. 사실이 아니기 때문에 실제로 추출 할 수있는 날짜/시간 정보는 온라인 문서에서 확인합니다 : 나 자신을 빌드 버전을 설정할하지만 여전히 나는 AssemblyVersion (이 같은 것을 사용하므로 자동 날짜/시간 스탬프를 원하는 http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx?CommentPosted=true#commentmessage

: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute.aspx

이 블로그를 참조하십시오 "1.0 *.")

다음은 빌드 날짜/시간을 추출하는 샘플 함수입니다.

private System.DateTime BuildDate() 
{ 

//This ONLY works if the assembly was built using VS.NET and the assembly version attribute is set to something like the below. The asterisk (*) is the important part, as if present, VS.NET generates both the build and revision numbers automatically. 
//<Assembly: AssemblyVersion("1.0.*")> 
//Note for app the version is set by opening the 'My Project' file and clicking on the 'assembly information' button. 
//An alternative method is to simply read the last time the file was written, using something similar to: 
//Return System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly.Location) 

//Build dates start from 01/01/2000 

System.DateTime result = DateTime.Parse("1/1/2000"); 

//Retrieve the version information from the assembly from which this code is being executed 

System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; 

//Add the number of days (build) 

result = result.AddDays(version.Build); 

//Add the number of seconds since midnight (revision) multiplied by 2 

result = result.AddSeconds(version.Revision * 2); 

//If we're currently in daylight saving time add an extra hour 

if (TimeZone.IsDaylightSavingTime(System.DateTime.Now, TimeZone.CurrentTimeZone.GetDaylightChanges(System.DateTime.Now.Year))) 
{ 
    result = result.AddHours(1); 
} 

return result; 

} 
+0

이것은 매우 유용하며 AssemblyInfo에서 한 가지 빠른 변경 이외의 다른 것을 요구하지 않는다. .cs! :-) – Filip

33

실행중인 어셈블리의 날짜 만 사용하기로했습니다. 파일을 게시하는 방식으로 정상적으로 작동합니다.

lblVersion.Text = String.Format("Version: {0}<br>Dated: {1}", 
    System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), 
    System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToShortDateString()); 
+0

저는 빌드 번호가 증가하므로 일부 게시물이 버전 번호와 함께 사용하는 '초의 수'- 보라색 - 마법을 사용할 수 없습니다. –