2012-09-12 70 views
6

默認的AssemblyInfo.cs看起來是這樣的:在AssemblyInfo.cs中需要什麼?

using System.Reflection; 
using System.Runtime.CompilerServices; 
using System.Runtime.InteropServices; 

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information 
// associated with an assembly. 
[assembly: AssemblyTitle("Foobar")] 
[assembly: AssemblyDescription("")] 
[assembly: AssemblyConfiguration("")] 
[assembly: AssemblyCompany("")] 
[assembly: AssemblyProduct("Foobar")] 
[assembly: AssemblyCopyright("Copyright © 2012")] 
[assembly: AssemblyTrademark("")] 
[assembly: AssemblyCulture("")] 

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components. If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type. 
[assembly: ComVisible(false)] 

// The following GUID is for the ID of the typelib if this project is exposed to COM 
[assembly: Guid("e8cd5d7d-5fba-4fe1-a753-f0cc6e052bf2")] 

// Version information for an assembly consists of the following four values: 
// 
//  Major Version 
//  Minor Version 
//  Build Number 
//  Revision 
// 
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below: 
// [assembly: AssemblyVersion("1.0.*")] 
[assembly: AssemblyVersion("1.0.0.0")] 
[assembly: AssemblyFileVersion("1.0.0.0")] 

所有這一切是真的有必要嗎?例如,如果我不需要,我可以刪除Guid和ComVisible,或者AssemblyTrademark,因爲它只是空的?

+1

當你嘗試過時發生了什麼? –

+3

好吧,它沒有崩潰,但想知道是否有任何我不知道的更大的影響,比如裝配在某些情況下無法使用:) – Svish

+0

我能想到的唯一可能的問題是將多個副本GAC中的程序集。您可以在其中放置多個版本的程序集。如果每個副本具有不同的文化,則可以擁有相同版本的多個副本。但是,如果版本信息丟失,爲什麼這可能是一個問題。 –

回答

9

這只是元數據 - 它們都不是需要

ComVisibleGuid只有在您使用程序集進行COM互操作時才需要。其他屬性最終成爲DLL上的元數據(通過Windows資源管理器中文件屬性對話框的Version選項卡可見)。

您可以刪除該文件,並且您的應用程序將編譯得很好,雖然它沒有元數據,並且不會顯示COM。

3

確實必要的不是任何屬性。但建議使用它們!

[assembly: AssemblyVersion("1.0.0.0")] 

AssemblyVersion爲程序集提供了一個版本,並用於從CLR中識別程序集(StrongName)。 AssemblyFileVersion只是FileDialog上的一個屬性。

[assembly: AssemblyInformationalVersion("1.0.0.0")] 

你可以但有任何其他的版本信息你喜歡。 另一個非常好的屬性如下:

[assembly: SuppressIldasm] 

這是抑制ILDASM打開你的組件來看看IL代碼。

還有很多關於裝配屬性的文章。你可以看看MSDN的更多信息。

+4

'SuppressIldasmAttribute'什麼都不做,只是「請求」'ildasm.exe'不爲你的程序集輸出IL。 *絕不會保護你的代碼。 – tomfanning

+0

你是對的,但對於那些對如何偵察IL來說並不十分了解的人來說,這將會停滯不前。 –

+0

啓動Reflector或ILSpy並不需要很多知識。 – tomfanning