RunInstallerAttribute 类

指定在安装程序集时是否应调用 Visual Studio 自定义操作安装程序或安装程序工具 (Installutil.exe)

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class)> _
Public Class RunInstallerAttribute
    Inherits Attribute
用法
Dim instance As RunInstallerAttribute
[AttributeUsageAttribute(AttributeTargets.Class)] 
public class RunInstallerAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class)] 
public ref class RunInstallerAttribute : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class) */ 
public class RunInstallerAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class) 
public class RunInstallerAttribute extends Attribute

备注

如果通过将 RunInstallerAttribute 设置为 true 标记从 Installer 继承的类,则在安装程序集时将调用 Visual Studio 自定义操作安装程序或 InstallUtil.exe。通过将 RunInstallerAttribute 设置为 false 标记的成员不会调用安装程序。默认为 false

提示

当使用设置为 trueRunInstallerAttribute 标记某个属性 (Property) 时,此属性 (Attribute) 的值会被设置为常数成员 Yes。对于通过将 RunInstallerAttribute 设置为 false 进行标记的属性,此值为 No。因此,若要检查代码中此属性的值,必须将该属性指定为 RunInstallerAttribute.YesRunInstallerAttribute.No

有关更多信息,请参见 属性 (Attribute) 概述利用属性扩展元数据

示例

下面的示例指定应为 MyProjectInstaller 运行安装程序。

<RunInstallerAttribute(True)> _
Public Class MyProjectInstaller
    Inherits Installer

    ' Insert code here.
End Class 'MyProjectInstaller
[RunInstallerAttribute(true)]
 public class MyProjectInstaller : Installer {
    // Insert code here.
 }
[RunInstallerAttribute(true)]
ref class MyProjectInstaller: public Installer{
   // Insert code here.
};
/** @attribute RunInstallerAttribute(true)
 */
public static class MyProjectInstaller extends Installer
{
    // Insert code here.
} //MyProjectInstaller

下一个示例创建 MyProjectInstaller 的实例。然后获取该类的属性,提取 RunInstallerAttribute,并输出是否运行安装程序。

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
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;
 }
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 void main(String[] args)
{
    // 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.get_Item(
        RunInstallerAttribute.class.ToType())));

    Console.WriteLine(("Run the installer? " 
        + System.Convert.ToString(myAttribute.get_RunInstaller())));
} //main

继承层次结构

System.Object
   System.Attribute
    System.ComponentModel.RunInstallerAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

RunInstallerAttribute 成员
System.ComponentModel 命名空间
Attribute
Installer