我从http://bootstrap.codeplex.com/下载了 bootstrap.exe ,我设法让它在本地 IIS 中工作。在 Application_Start() 并使用 Process.Start()
但是在 Windows Azure 上,根本不起作用。我确定文件在那里并且没有错误消息。
但没有文件下载和解压缩。我尝试了“本地资源”文件夹或本地文件夹
这里有人有工作代码吗?
我从http://bootstrap.codeplex.com/下载了 bootstrap.exe ,我设法让它在本地 IIS 中工作。在 Application_Start() 并使用 Process.Start()
但是在 Windows Azure 上,根本不起作用。我确定文件在那里并且没有错误消息。
但没有文件下载和解压缩。我尝试了“本地资源”文件夹或本地文件夹
这里有人有工作代码吗?
首先,您需要将 bootstrapper.exe 作为项目的一部分(添加 -> 现有项目 -> 浏览到 bootstrapper.exe & .config 包括它们两者)。对于这些文件的属性,您必须将“构建操作”设置为“无”,将“复制到输出目录”设置为“始终复制”。
现在您可以使用以下代码来运行引导程序(我就是这样做的并且它可以工作):
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% 测试和工作的代码!