RunInstallerAttribute 类

定义

指定在安装程序集时是否应调用 Visual Studio 自定义操作安装程序或 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

下一个示例创建 MyProjectInstaller的实例。The 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. 标记有 RunInstallerAttribute 设置为 false 的成员将不会调用安装程序。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的属性,值为 NoFor a property marked with the RunInstallerAttribute set to false, the value is No. 因此,当你想要在代码中检查此属性的值时,必须将属性指定为 RunInstallerAttribute.YesRunInstallerAttribute.NoTherefore, 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 自定义操作安装程序或 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 自定义操作安装程序或 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 的浅表副本。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)

将一组名称映射为对应的一组调度标识符。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)

适用于

另请参阅