InstallContext 클래스

정의

현재 설치에 대한 정보를 포함합니다.

public ref class InstallContext
public class InstallContext
type InstallContext = class
Public Class InstallContext
상속
InstallContext

예제

다음 예제는 InstallContext 생성자를 Parameters 속성 및 LogMessageIsParameterTrue 의 메서드는 InstallContext 클래스입니다.

경우는 Install 명령줄에서 매개 변수에 대 한 확인 설치 관리자의 메서드를 호출 합니다. 에 따라 콘솔에 진행률 메시지를 표시 하 고 지정된 된 로그 파일에 저장 됩니다.

빈 인수 없이 프로그램을 호출 하는 경우 InstallContext 만들어집니다. 때 "/ 로그 파일" 및 "/ LogtoConsole"를 지정 합니다 InstallContext 해당 인수를 전달 하 여 만들어집니다 InstallContext.

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

using namespace System;
using namespace System::ComponentModel;
using namespace System::Configuration::Install;
using namespace System::Collections;
using namespace System::Collections::Specialized;

[RunInstallerAttribute(true)]
ref class InstallContext_Example: public Installer
{
public:
   InstallContext^ myInstallContext;
   virtual void Install( IDictionary^ mySavedState ) override
   {
      StringDictionary^ myStringDictionary = myInstallContext->Parameters;
      if ( myStringDictionary->Count == 0 )
      {
         Console::Write( "No parameters have been entered in the command line " );
         Console::WriteLine( "hence, the install will take place in the silent mode" );
      }
      else
      {
         // Check whether the "LogtoConsole" parameter has been set.
         if ( myInstallContext->IsParameterTrue( "LogtoConsole" ) )
         {
            // Display the message to the console and add it to the logfile.
            myInstallContext->LogMessage( "The 'Install' method has been called" );
         }
      }
      // The 'Install procedure should be added here.
   }

   virtual void Uninstall( IDictionary^ mySavedState ) override
   {
      // The 'Uninstall' procedure should be added here.
   }

   virtual void Rollback( IDictionary^ mySavedState ) override
   {
      if ( myInstallContext->IsParameterTrue( "LogtoConsole" ) )
      {
         myInstallContext->LogMessage( "The 'Rollback' method has been called" );
      }

      // The 'Rollback' procedure should be added here.
   }

   virtual void Commit( IDictionary^ mySavedState ) override
   {
      if ( myInstallContext->IsParameterTrue( "LogtoConsole" ) )
      {
         myInstallContext->LogMessage( "The 'Commit' method has been called" );
      }

      // The 'Commit' procedure should be added here.
   }
};

int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   InstallContext_Example^ myInstallObject = gcnew InstallContext_Example;
   IDictionary^ mySavedState = gcnew Hashtable;
   if ( args->Length < 2 )
   {
      // There are no command line arguments, create an empty 'InstallContext'.
      myInstallObject->myInstallContext = gcnew InstallContext;
   }
   else
   if ( (args->Length == 2) && (args[ 1 ]->Equals( "/?" )) )
   {
      // Display the 'Help' for this utility.
      Console::WriteLine( "Specify the '/Logfile' and '/LogtoConsole' parameters" );
      Console::WriteLine( "Example: " );
      Console::WriteLine( "InstallContext_InstallContext.exe /LogFile=example.log  /LogtoConsole=true" );
      return 0;
   }
   else
   {
      // Create an InstallContext object with the given parameters.
      array<String^>^commandLine = gcnew array<String^>(args->Length - 1);
      for ( int i = 0; i < args->Length - 1; i++ )
      {
         commandLine[ i ] = args[ i + 1 ];
      }
      myInstallObject->myInstallContext = gcnew InstallContext( args[ 1 ],commandLine );
   }

   try
   {
      // Call the 'Install' method.
      myInstallObject->Install( mySavedState );
      
      // Call the 'Commit' method.
      myInstallObject->Commit( mySavedState );
   }
   catch ( Exception^ ) 
   {
      // Call the 'Rollback' method.
      myInstallObject->Rollback( mySavedState );
   }
}
using System;
using System.ComponentModel;
using System.Configuration.Install;
using System.Collections;
using System.Collections.Specialized;

namespace MyInstallContextNamespace
{
   [RunInstallerAttribute(true)]
   class InstallContext_Example : Installer
   {
      public InstallContext myInstallContext;

      public override void Install( IDictionary mySavedState )
      {
         base.Install( mySavedState );
         StringDictionary myStringDictionary = myInstallContext.Parameters;
         if( myStringDictionary.Count == 0 )
         {
            Console.WriteLine( "No parameters have been entered in the command line "
               +"hence, the install will take place in the silent mode" );
         }
         else
         {
            // Check whether the "LogtoConsole" parameter has been set.
            if( myInstallContext.IsParameterTrue( "LogtoConsole" ) == true )
            {
               // Display the message to the console and add it to the logfile.
               myInstallContext.LogMessage( "The 'Install' method has been called" );
            }
         }

         // The 'Install procedure should be added here.
      }

      public override void Uninstall( IDictionary mySavedState )
      {
         base.Uninstall( mySavedState );
         // The 'Uninstall' procedure should be added here.
      }

      public override void Rollback( IDictionary mySavedState )
      {
         base.Rollback( mySavedState );
         if( myInstallContext.IsParameterTrue( "LogtoConsole" ) == true )
         {
            myInstallContext.LogMessage( "The 'Rollback' method has been called" );
         }

         // The 'Rollback' procedure should be added here.
      }

      public override void Commit( IDictionary mySavedState )
      {
         base.Commit( mySavedState );
         if( myInstallContext.IsParameterTrue( "LogtoConsole" ) == true )
         {
            myInstallContext.LogMessage( "The 'Commit' method has been called" );
         }

         // The 'Commit' procedure should be added here.
      }

      static void Main( string[] args )
      {
         InstallContext_Example myInstallObject = new InstallContext_Example();

         IDictionary mySavedState = new Hashtable();

         if( args.Length < 1 )
         {
            // There are no command line arguments, create an empty 'InstallContext'.
            myInstallObject.myInstallContext = new InstallContext();
         }

         else if( ( args.Length == 1 ) && ( args[ 0 ] == "/?" ) )
         {
            // Display the 'Help' for this utility.
            Console.WriteLine( "Specify the '/Logfile' and '/LogtoConsole' parameters" );
            Console.WriteLine( "Example: " );
            Console.WriteLine( "InstallContext_InstallContext.exe /LogFile=example.log"
                                          +" /LogtoConsole=true" );
            return;
         }

         else
         {
            // Create an InstallContext object with the given parameters.
            String[] commandLine = new string[ args.Length ];
            for( int i = 0; i < args.Length; i++ )
            {
               commandLine[ i ] = args[ i ];
            }
            myInstallObject.myInstallContext = new InstallContext( args[ 0 ], commandLine);
         }

         try
         {
            // Call the 'Install' method.
            myInstallObject.Install( mySavedState );

            // Call the 'Commit' method.
            myInstallObject.Commit( mySavedState );
         }
         catch( Exception )
         {
            // Call the 'Rollback' method.
            myInstallObject.Rollback( mySavedState );
         }
      }
   }
}
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Collections
Imports System.Collections.Specialized

Namespace MyInstallContextNamespace
   <RunInstallerAttribute(True)> Class InstallContext_Example
      Inherits Installer
      Public myInstallContext As InstallContext

      Public Overrides Sub Install(mySavedState As IDictionary)
         Dim myStringDictionary As StringDictionary = myInstallContext.Parameters
         If myStringDictionary.Count = 0 Then
            Console.WriteLine("No parameters have been entered in the command line" + _
                        "hence, the install will take place in the silent mode")
         Else
            ' Check wether the "LogtoConsole" parameter has been set.
            If myInstallContext.IsParameterTrue("LogtoConsole") = True Then
               ' Display the message to the console and add it to the logfile.
               myInstallContext.LogMessage("The 'Install' method has been called")
            End If
         End If
         ' The 'Install procedure should be added here.
      End Sub

      Public Overrides Sub Uninstall(mySavedState As IDictionary)
         ' The 'Uninstall' procedure should be added here.
      End Sub

      Public Overrides Sub Rollback(mySavedState As IDictionary)
         If myInstallContext.IsParameterTrue("LogtoConsole") = True Then
            myInstallContext.LogMessage("The 'Rollback' method has been called")
         End If
         ' The 'Rollback' procedure should be added here.
      End Sub

      Public Overrides Sub Commit(mySavedState As IDictionary)
         If myInstallContext.IsParameterTrue("LogtoConsole") = True Then
            myInstallContext.LogMessage("The 'Commit' method has been called")
         End If
         ' The 'Commit' procedure should be added here.
      End Sub

      ' Entry point which delegates to C-style main Private Function
      Public Overloads Shared Sub Main()
         Main(System.Environment.GetCommandLineArgs())
      End Sub

      Overloads Shared Sub Main(args() As String)
         Dim myInstallObject As New InstallContext_Example()
         Dim mySavedState = New Hashtable()

         If args.Length < 2 Then
            ' There are no command line arguments, create an empty 'InstallContext'.
            myInstallObject.myInstallContext = New InstallContext()
         ElseIf args.Length = 2 And args(1) = "/?" Then
               ' Display the 'Help' for this utility.
               Console.WriteLine("Specify the '/Logfile' and '/LogtoConsole' parameters")
               Console.WriteLine("Example: ")
               Console.WriteLine("InstallContext_InstallContext.exe /LogFile=example.log" + _
                                                         " /LogtoConsole=true")
               Return

         Else
            ' Create an InstallContext object with the given parameters.
            Dim commandLine() As String = New String(args.Length - 2) {}
            Dim i As Integer
            For i = 1 To args.Length - 1
               commandLine(i-1) = args(i)
            Next i
            myInstallObject.myInstallContext = _
               New InstallContext("/LogFile:example.log", commandLine)
         End If

         Try
            ' Call the 'Install' method.
            myInstallObject.Install(mySavedState)

            ' Call the 'Commit' method.
            myInstallObject.Commit(mySavedState)
         Catch
            ' Call the 'Rollback' method.
            myInstallObject.Rollback( mySavedState )
         End Try
      End Sub
   End Class
End Namespace 'MyInstallContextNamespace

설명

일반적으로 InstallContext 예: InstallUtil.exe 어셈블리를 설치 하는 실행 가능한 설치 프로그램에 의해 생성 됩니다. 설치 프로그램에서 호출 된 InstallContext 생성자, 기본 로그 파일 경로 및 명령줄 매개 변수를 전달 합니다.

호출 하기 전에 해당 Install, Commit, Rollback, 또는 Uninstall 설치 프로그램을 설정 하는 메서드를를 Context 속성을 Installer 인스턴스의 InstallContext합니다. 이러한 메서드를 호출 하기 전에 Installer 에서 설치 관리자 컬렉션을 포함 하는 합니다 Installers 속성 집합을 Context 각 포함 된 설치 관리자의 속성입니다.

Parameters 속성 설치 실행 파일을 실행 하기 위해 입력 되는 명령줄의 구문 분석 된 버전을 포함 합니다. 속성을 사용 하면 로그 파일, 콘솔에 로그 정보를 표시할 것인지 및 설치 하는 동안 사용자 인터페이스를 표시할지 여부를 경로 같은 정보가 있습니다. 호출 된 IsParameterTrue 명령줄 매개 변수 인지 확인 하는 방법 true합니다.

사용 된 LogMessage 설치 로그 파일 및 콘솔에 상태 메시지를 작성 하는 방법입니다.

생성자

InstallContext()

InstallContext 클래스의 새 인스턴스를 초기화합니다.

InstallContext(String, String[])

InstallContext 클래스의 새 인스턴스를 초기화하고, 설치 로그 파일을 만듭니다.

속성

Parameters

InstallUtil.exe를 실행 시 입력했던 명령줄 매개 변수를 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsParameterTrue(String)

지정한 명령줄 매개 변수가 true인지 여부를 확인합니다.

LogMessage(String)

콘솔과 설치 로그 파일에 메시지를 씁니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ParseCommandLine(String[])

명령줄 매개 변수의 구문을 분석하여 문자열 사전에 포함시킵니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보