RunInstallerAttribute 類別

定義

指定在安裝組件時是否應該叫用 Visual Studio Custom Action Installer 或 Installutil.exe (安裝程式工具)Specifies whether the Visual Studio Custom Action Installer or the Installutil.exe (Installer Tool) should be invoked when the assembly is installed.

public ref class RunInstallerAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public class RunInstallerAttribute : Attribute
type RunInstallerAttribute = class
    inherit Attribute
Public Class RunInstallerAttribute
Inherits Attribute
繼承
RunInstallerAttribute
屬性

範例

下列範例會指定應該針對MyProjectInstaller執行安裝程式。The following example specifies that the installer should be run for MyProjectInstaller.

[RunInstallerAttribute(true)]
ref class MyProjectInstaller: public Installer{
   // Insert code here.
};
[RunInstallerAttribute(true)]
 public class MyProjectInstaller : Installer {
    // Insert code here.
 }
<RunInstallerAttribute(True)> _
Public Class MyProjectInstaller
    Inherits Installer

    ' Insert code here.
End Class

下一個範例會建立的實例MyProjectInstallerThe next example creates an instance of MyProjectInstaller. 然後, 它會取得類別的屬性、解壓縮RunInstallerAttribute, 並列印是否要執行安裝程式。Then it gets the attributes for the class, extracts the RunInstallerAttribute, and prints whether to run the installer.

int main()
{
   // Creates a new installer.
   MyProjectInstaller^ myNewProjectInstaller = gcnew MyProjectInstaller;

   // Gets the attributes for the collection.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewProjectInstaller );

   /* Prints whether to run the installer by retrieving the 
       * RunInstallerAttribute from the AttributeCollection. */
   RunInstallerAttribute^ myAttribute = dynamic_cast<RunInstallerAttribute^>(attributes[ RunInstallerAttribute::typeid ]);
   Console::WriteLine( "Run the installer? {0}", myAttribute->RunInstaller );
   return 0;
}
public static int Main() {
    // Creates a new installer.
    MyProjectInstaller myNewProjectInstaller = new MyProjectInstaller();
 
    // Gets the attributes for the collection.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewProjectInstaller);
 
    /* Prints whether to run the installer by retrieving the 
     * RunInstallerAttribute from the AttributeCollection. */
    RunInstallerAttribute myAttribute = 
       (RunInstallerAttribute)attributes[typeof(RunInstallerAttribute)];
    Console.WriteLine("Run the installer? " + myAttribute.RunInstaller.ToString());
  
    return 0;
 }
Public Shared Function Main() As Integer
    ' Creates a new installer.
    Dim myNewProjectInstaller As New MyProjectInstaller()
    
    ' Gets the attributes for the collection.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewProjectInstaller)
    
    ' Prints whether to run the installer by retrieving the
    ' RunInstallerAttribute from the AttributeCollection. 
    Dim myAttribute As RunInstallerAttribute = _
        CType(attributes(GetType(RunInstallerAttribute)), RunInstallerAttribute)

    Console.WriteLine(("Run the installer? " & myAttribute.RunInstaller.ToString()))
    Return 0
End Function 'Main

備註

如果繼承自Installer的類別標記為, 則會RunInstallerAttribute將設定true為, Visual Studio 的自訂動作安裝程式或 installutil.exe 會在安裝元件時叫用。If a class that inherits from Installer is marked with the RunInstallerAttribute set to true, Visual Studio's Custom Action Installer or the InstallUtil.exe will be invoked when the assembly is installed. 以設定為falseRunInstallerAttribute成員, 將不會叫用安裝程式。Members marked with the RunInstallerAttribute set to false will not invoke an installer. 預設為 trueThe default is true.

注意

當您將設定為的RunInstallerAttribute屬性標記為true時, 這個屬性的值會設定為常數成員。 YesWhen you mark a property with the RunInstallerAttribute set to true, the value of this attribute is set to the constant member Yes. 對於以設定為RunInstallerAttribute false的標記的屬性, 此值No為。For a property marked with the RunInstallerAttribute set to false, the value is No. 因此, 當您想要在程式碼中檢查這個屬性的值時, 您必須將屬性指定RunInstallerAttribute.YesRunInstallerAttribute.No或。Therefore, when you want to check the value of this attribute in your code, you must specify the attribute as RunInstallerAttribute.Yes or RunInstallerAttribute.No.

如需詳細資訊,請參閱屬性For more information, see Attributes.

建構函式

RunInstallerAttribute(Boolean)

初始化 RunInstallerAttribute 類別的新執行個體。Initializes a new instance of the RunInstallerAttribute class.

欄位

Default

設定預設可見度,即 NoSpecifies the default visibility, which is No. 這個 static 欄位是唯讀的。This static field is read-only.

No

指定在安裝組件時不要叫用 Visual Studio Custom Action Installer 或 Installutil.exe (安裝程式工具)Specifies that the Visual Studio Custom Action Installer or the Installutil.exe (Installer Tool) should not be invoked when the assembly is installed. 這個 static 欄位是唯讀的。This static field is read-only.

Yes

指定在安裝組件時應該要叫用 Visual Studio Custom Action Installer 或 Installutil.exe (安裝程式工具)Specifies that the Visual Studio Custom Action Installer or the Installutil.exe (Installer Tool) should be invoked when the assembly is installed. 這個 static 欄位是唯讀的。This static field is read-only.

屬性

RunInstaller

取得值,指出在安裝組件時是否要叫用安裝程式。Gets a value indicating whether an installer should be invoked during installation of an assembly.

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)

方法

Equals(Object)

判斷指定之 RunInstallerAttribute 的值是否與目前的 RunInstallerAttribute 相等。Determines whether the value of the specified RunInstallerAttribute is equivalent to the current RunInstallerAttribute.

GetHashCode()

產生目前 RunInstallerAttribute 的雜湊程式碼。Generates a hash code for the current RunInstallerAttribute.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。Determines if this attribute is the default.

Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)

適用於

另請參閱