次の方法で共有


AssemblyInstaller.CheckIfInstallable メソッド

指定したアセンブリをインストールできるかどうかを確認します。

Public Shared Sub CheckIfInstallable( _
   ByVal assemblyName As String _)
[C#]
public static void CheckIfInstallable(stringassemblyName);
[C++]
public: static void CheckIfInstallable(String* assemblyName);
[JScript]
public static function CheckIfInstallable(
   assemblyName : String);

パラメータ

  • assemblyName
    インストーラを検索する対象のアセンブリ。

例外

例外の種類 条件
Exception 指定したアセンブリをインストールできません。

解説

CheckIfInstallable メソッドは、指定したアセンブリをインストールできるかどうかを判断します。例外がスローされないようにするには、ファイルが次の基準を満たしている必要があります。

  • ファイルが存在する。
  • ファイルが .NET Framework アセンブリである。
  • ファイルからパブリック型を読み取ることができる。
  • Installer クラスを拡張する非抽象パブリック クラスが少なくとも 1 つ存在し、そのクラスに RunInstallerAttribute.Yes 属性が格納されている。
  • 各インストーラのインスタンスを作成できる。

メモ   アセンブリが有効であっても、インストーラが格納されていない場合は、例外がスローされます。この動作はインストール時の動作とは異なります。インストール時には、空のアセンブリをインストールしてもエラーにはなりません。

使用例

[Visual Basic, C#, C++] 存在するアセンブリと存在しないアセンブリの両方に対して CheckIfInstallable メソッドを呼び出し、その結果をコンソールに表示する例を次に示します。

 
Imports System
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 'Main

End Class 'MyCheckIfInstallableClass 

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


   }
}

[C++] 
#using <mscorlib.dll>
#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(S"MyAssembly_CheckIfInstallable.exe");

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

        // Determine whether the assembly 'NonExistant' is installable.
        AssemblyInstaller::CheckIfInstallable(S"NonExistant");
    } catch (Exception* e) {
        Console::WriteLine(e);
    }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

AssemblyInstaller クラス | AssemblyInstaller メンバ | System.Configuration.Install 名前空間