AssemblyInstaller.CheckIfInstallable(String) 方法

定義

檢查是否可以安裝指定的組件。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)

參數

assemblyName
String

要在其中搜尋安裝程式的組件。The assembly in which to search for installers.

例外狀況

指定的組件無法安裝。The specified assembly cannot be installed.

範例

在下列範例中, CheckIfInstallable方法會套用至存在和不存在的元件,而呼叫的結果會顯示在主控台中。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

備註

CheckIfInstallable方法會判斷是否可以安裝指定的元件。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.

  • 檔案是 .NET Framework 元件。The file is a .NET Framework assembly.

  • 公用類型可以從檔案讀取。The public types can be read from the file.

  • 至少有一個公用、非抽象的類別會擴充Installer類別並Yes包含屬性。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.

注意

如果元件有效,但未包含任何安裝程式,則會擲回例外狀況。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.

適用於