2010-06-15 2 views

답변

2

한 가지 해결책은 빌드 중에이 정보를 어셈블리 특성에 포함시키는 것입니다. 당신은 MSBuild에서 커뮤니티 작업 시간과 어셈블리 정보 작업을 사용하여이 작업을 수행 할 수 있습니다

<Time> 
    <Output TaskParameter="Month" PropertyName="Month" /> 
    <Output TaskParameter="Day" PropertyName="Day" /> 
    <Output TaskParameter="Year" PropertyName="Year" /> 
    <Output TaskParameter="Hour" PropertyName="Hour" /> 
    <Output TaskParameter="Minute" PropertyName="Minute" /> 
    <Output TaskParameter="Second" PropertyName="Second" /> 
</Time> 

<AssemblyInfo CodeLanguage="CS" 
    OutputFile="$(MSBuildProjectDirectory)\GlobalInfo.cs" 
    AssemblyDescription="This page was last updated: $(Month)/$(Day)/$(Year)" 
/> 

당신은 프로젝트의 소스 파일 (이 예에서는 GlobalInfo.cs)를 포함한다. 코드에서이 값에 액세스하려면 다음과 같이 사용하십시오.

public static string GetAssemblyDescription(Type t) 
{ 
    string result = String.Empty; 
    var items = t.Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); 
    if (items != null && items.Length > 0) 
    { 
     AssemblyDescriptionAttribute attrib = (AssemblyDescriptionAttribute)items[0]; 
     result = attrib.Description; 
    } 
    return result; 
} 

Type t = typeof(MyClass); 
string description = GetAssemblyDescription(t); 
Console.WriteLine(description);