InstallContext 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 InstallContext 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| InstallContext() |
初始化 InstallContext 類別的新執行個體。 |
| InstallContext(String, String[]) |
初始化該類別的新實例 InstallContext ,並為安裝建立日誌檔。 |
InstallContext()
初始化 InstallContext 類別的新執行個體。
public:
InstallContext();
public InstallContext();
Public Sub New ()
範例
備註
這個範例展示了如何使用其中一個超載版本 InstallContext 的建構子。 其他可能可用的範例,請參閱個別超載主題。
當程式被呼叫且未輸入任何參數時,會產生一個空 InstallContext 。
// There are no command line arguments, create an empty 'InstallContext'.
myInstallObject->myInstallContext = gcnew InstallContext;
// There are no command line arguments, create an empty 'InstallContext'.
myInstallObject.myInstallContext = new InstallContext();
' There are no command line arguments, create an empty 'InstallContext'.
myInstallObject.myInstallContext = New InstallContext()
備註
這種過載並不會產生安裝的日誌檔。
適用於
InstallContext(String, String[])
初始化該類別的新實例 InstallContext ,並為安裝建立日誌檔。
public:
InstallContext(System::String ^ logFilePath, cli::array <System::String ^> ^ commandLine);
public InstallContext(string logFilePath, string[] commandLine);
new System.Configuration.Install.InstallContext : string * string[] -> System.Configuration.Install.InstallContext
Public Sub New (logFilePath As String, commandLine As String())
參數
- logFilePath
- String
此安裝的日誌檔案路徑,或 null 若不建立日誌檔案,則需建立。
- commandLine
- String[]
執行安裝程式 null 時或未輸入時,命令列參數會被輸入。
範例
此範例摘自該類別概述 InstallContext 中的範例。
當指定「/LogFile」與「/LogtoConsole」時, InstallContext 會將相應的參數傳遞給 InstallContext。
// 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 );
// 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);
' 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)
備註
若安裝使用Installutil.exe( 安裝工具),此建構子會在指定路徑建立日誌檔,並將命令列參數陣列解析至該 Parameters 屬性中。 如果命令列參數中指定了日誌檔案路徑,則會用它來建立檔案。 若指令列未指定日誌檔參數,則使用該參數的 logFilePath 值。 若要抑制日誌檔案的建立,請傳遞「/logfile= 」的命令列參數。
給呼叫者的注意事項
呼叫這個建構子時,在參數中傳遞你的預設日誌檔案路徑 logFilePath 。 除非執行安裝檔時使用 /logfile 命令列參數,否則日誌檔案就是在此建立。