まず、プロジェクトの一部としてbootstrapper.exeを追加する必要があります(追加 - >既存アイテム - > bootstrapper.exe & .configファイルを参照してください)。これらのファイルのプロパティでは、 "Build Action"を "None"に設定し、 "Copy to output directory"を "Copy always"に設定する必要があります。
は今、あなたは(私はそのようにそれを行うと、それは動作します)ブートストラップを実行するには、次のコードを使用することができます。
internal void SomethingWithBootStrapper()
{
//
Trace.TraceInformation("Trying to install agent...");
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "bootstrapper.exe");
psi.Arguments = @"-get http://some_url_to_download_something.com/path/to/file.zip -lr $lr(YourLocalResourceKeyHere) -unzip $lr(YourLocalResourceKeyHere)\extract -run $lr(YourLocalResourceKeyHere)\extract\Setup.exe -args /some /args /for_the_setup.exe -block";
Trace.WriteLine("Calling " + psi.FileName + " " + psi.Arguments + " ...");
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = false;
psi.RedirectStandardError = true;
// run elevated
psi.Verb = "runas";
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(psi))
{
exeProcess.PriorityClass = ProcessPriorityClass.High;
string outString = string.Empty;
// use ansynchronous reading for at least one of the streams
// to avoid deadlock
exeProcess.OutputDataReceived += (s, e) =>
{
outString += e.Data;
};
exeProcess.BeginOutputReadLine();
// now read the StandardError stream to the end
// this will cause our main thread to wait for the
// stream to close (which is when ffmpeg quits)
string errString = exeProcess.StandardError.ReadToEnd();
Trace.WriteLine(outString);
Trace.TraceError(errString);
this._isInitialized = true;
}
}
catch (Exception e)
{
Trace.TraceError(e.Message);
this._isInitialized = false;
}
}
注意してください、これは100%をテストし、コードを動作していること!
ありがとう、あなたの提案は私に思い出させる、私は "BootStrapper.exe.config"ファイルを忘れる。これはローカルのIISで動作するので、私はもうこのファイルについては考えていませんでした。( –
とにかくこのファイルをAzureに置くだけで、すべてが動作します。 –
@astaykov - 奇妙なことから、コマンドをバットファイルに入れてスタートアップのタスクからですか?それは私がブートストラップを構築した初期のユースケースでした。 – dunnry