我使用选项 1。这些天更新程序进程很少更新。它使用一个 XML 文件,其中包含从何处获取文件的详细信息(当前支持 SVN,正在努力添加 NuGet 支持)以及放置它们的位置。它还指定哪些是服务,哪些是网站,并指定要用于每个项目的服务的名称。
该过程轮询源,如果有可用的新版本,它将其复制到新版本编号的目录,然后更新服务。它还保留每个更新的 5 个副本,以便在出现问题时轻松回滚。
这是更新程序的核心代码,它停止现有服务,复制文件,然后重新启动它。
if (isService)
{
log.Debug("Stopping service " + project.ServiceName);
var service = GetService(project);
if (service != null &&
service.Status != System.ServiceProcess.ServiceControllerStatus.Stopped && service.Status != System.ServiceProcess.ServiceControllerStatus.StopPending)
{
service.Stop();
}
service.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, new TimeSpan(0, 1, 0));
if (service.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
log.Debug("Service stopped");
else
log.Error("ERROR: Expected Stopped by Service is " + service.Status);
}
log.Debug("Copying files over");
CopyFolder(checkoutDirectory, destinationDirectory);
if (isService)
{
log.Debug("Starting service");
var service = GetService(project);
// Currently it doesn't create services, you need to do that manually
if (service != null)
{
service.Start();
service.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, 1, 0));
if (service.Status == System.ServiceProcess.ServiceControllerStatus.Running)
log.Debug("Service running");
else
log.Error("Service " + service.Status);
}
}