如何在运行时获取执行中的Service Fabric服务(和应用程序)版本?我已经尝试了下,但两者StatefulServiceContext
并StatelessServiceContext
没有提供这些信息。
您可以FabricClient
用来获取此信息。
对于应用程序版本:
var applicationName = new Uri("fabric:/MyApp"); // or use Context.CodePackageActivationContext.ApplicationName
using (var client = new FabricClient())
{
var applications = await client.QueryManager.GetApplicationListAsync(applicationName).ConfigureAwait(false);
var version = applications[0].ApplicationTypeVersion;
}
对于服务版本-
从服务类中:
Context.CodePackageActivationContext.GetServiceManifestVersion()
或者:
var serviceName = new Uri("fabric:/MyApp/MyService"); // or use Context.ServiceName
using (var client = new FabricClient())
{
var services = await client.QueryManager.GetServiceListAsync(applicationName, serviceName).ConfigureAwait(false);
var version = services[0].ServiceManifestVersion;
}
笔记:
FabricClient.ApplicationManager.GetApplicationUpgradeProgressAsync
并检索TargetApplicationTypeVersion
FabricClient
如果您经常使用它,可能要缓存(请参阅此处的备注)CodePackageActivationContext
还包含CodePackageVersion
,这是比服务清单版本不同本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句