Επεξεργασία

Κοινή χρήση μέσω


AssemblyInstaller.CheckIfInstallable(String) Method

Definition

Checks to see if the specified assembly can be installed.

public:
 static void CheckIfInstallable(System::String ^ assemblyName);
public static void CheckIfInstallable (string assemblyName);
static member CheckIfInstallable : string -> unit
Public Shared Sub CheckIfInstallable (assemblyName As String)

Parameters

assemblyName
String

The assembly in which to search for installers.

Exceptions

The specified assembly cannot be installed.

Examples

In the following example, the CheckIfInstallable method is applied to both an existent and nonexistent assembly and the results of the call are displayed to the console.

#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Configuration::Install;
int main()
{
   try
   {
      
      // Determine whether the assembly 'MyAssembly' is installable.
      AssemblyInstaller::CheckIfInstallable( "MyAssembly_CheckIfInstallable.exe" );
      Console::WriteLine( "The assembly 'MyAssembly_CheckIfInstallable' is installable" );
      
      // Determine whether the assembly 'NonExistant' is installable.
      AssemblyInstaller::CheckIfInstallable( "NonExistant" );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e );
   }

}
using System;
using System.Configuration.Install;

class MyCheckIfInstallableClass:Installer
{
   static void Main()
   {

      try
      {
         // Determine whether the assembly 'MyAssembly' is installable.
         AssemblyInstaller.CheckIfInstallable( "MyAssembly_CheckIfInstallable.exe" );

         Console.WriteLine( "The assembly 'MyAssembly_CheckIfInstallable' is installable" );

         // Determine whether the assembly 'NonExistant' is installable.
         AssemblyInstaller.CheckIfInstallable( "NonExistant" );
      }
      catch( Exception )
      {
      }
   }
}
Imports System.Configuration.Install

Class MyCheckIfInstallableClass
   
   Shared Sub Main()

      Try
         ' Determine whether the assembly 'MyAssembly' is installable.
         AssemblyInstaller.CheckIfInstallable("MyAssembly_CheckIfInstallable.exe")
         
         Console.WriteLine("The assembly 'MyAssembly_CheckIfInstallable' is installable")
         
         ' Determine whether the assembly 'NonExistant' is installable.
         AssemblyInstaller.CheckIfInstallable("NonExistant")
       Catch 
      End Try

   End Sub

End Class

Remarks

The CheckIfInstallable method determines whether the specified assembly can be installed. To avoid an exception being thrown, the file must meet the following criteria:

  • The file exists.

  • The file is a .NET Framework assembly.

  • The public types can be read from the file.

  • There is at least one public, non abstract class that extends the Installer class and contains the Yes attribute.

  • An instance of each installer can be created.

Note

If the assembly is valid but contains no installers, an exception is thrown. This behavior differs from that at install time, when it is not an error to install an empty assembly.

Applies to