AssemblyInstaller.CheckIfInstallable(String) 方法

定義

檢查是否可以安裝指定的組件。

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

要在其中搜尋安裝程式的組件。

例外狀況

指定的組件無法安裝。

範例

在下列範例中 CheckIfInstallable ,方法會同時套用至存在和不存在的元件,而呼叫的結果會顯示至控制台。

#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 會判斷是否可以安裝指定的元件。 若要避免擲回例外狀況,檔案必須符合下列準則:

  • 檔案存在。

  • 檔案是 .NET Framework元件。

  • 您可以從檔案讀取公用類型。

  • 至少有一個公用的非抽象類可擴充 Installer 類別,並包含 Yes 屬性。

  • 您可以建立每個安裝程式的實體。

注意

如果元件有效,但不包含任何安裝程式,則會擲回例外狀況。 當安裝空白元件時,此行為與安裝時間不同。

適用於