RunInstallerAttribute Class
TOC
Collapse the table of content
Expand the table of content

RunInstallerAttribute Class

Specifies whether the Visual Studio .NET Custom Action Installer or the Installer Tool (Installutil.exe) should be invoked when the assembly is installed.

For a list of all members of this type, see RunInstallerAttribute Members.

System.Object
   System.Attribute
      System.ComponentModel.RunInstallerAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.Class)>
Public Class RunInstallerAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.Class)]
public class RunInstallerAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::Class)]
public __gc class RunInstallerAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.Class)
class RunInstallerAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

If a class that inherits from Installer is marked with the RunInstallerAttribute constructor of the value true, Visual Studio .NET's Custom Action Installer or the InstallUtil.exe will be invoked when the assembly is installed. Members marked with the RunInstallerAttribute constructor of the value false will not invoke an installer. The default is false.

Note   When you mark a property with the RunInstallerAttribute constructor of the value true, the value of this attribute is set to the constant member Yes. For a property marked with the RunInstallerAttribute constructor of the value false, the value is 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 Overview.

Example

[Visual Basic, C#, C++] The following example specifies that the installer should be run for MyProjectInstaller.

[Visual Basic] 
<RunInstallerAttribute(True)> _
Public Class MyProjectInstaller
    Inherits Installer

    ' Insert code here.
End Class 'MyProjectInstaller

[C#] 
[RunInstallerAttribute(true)]
 public class MyProjectInstaller : Installer {
    // Insert code here.
 }

[C++] 
[RunInstallerAttribute(true)]
__gc class MyProjectInstaller : public Installer {
    // Insert code here.
};

[Visual Basic, C#, C++] The next example creates an instance of MyProjectInstaller. Then it gets the attributes for the class, extracts the RunInstallerAttribute, and prints whether to run the installer.

[Visual Basic] 
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

[C#] 
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;
 }

[C++] 
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 = 
        dynamic_cast<RunInstallerAttribute*>(attributes->Item[__typeof(RunInstallerAttribute)]);
    Console::WriteLine(S"Run the installer? {0}", __box(myAttribute->RunInstaller));

    return 0;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

RunInstallerAttribute Members | System.ComponentModel Namespace | Attribute | Installer

Show:
© 2016 Microsoft