如何在运行时获取正在执行的Service Fabric服务(和应用程序)版本?我已尝试过上下文,但StatefulServiceContext
和StatelessServiceContext
都没有提供该信息。
答案 0 :(得分:5)
您可以使用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
,可能需要对其进行缓存(请参阅remarks here)CodePackageActivationContext
还包含CodePackageVersion
,它与服务清单的版本不同答案 1 :(得分:1)
您也可以使用PowerShell。要获取应用程序类型版本:
Get-ServiceFabricApplication -ApplicationName fabric:/MyApplication | Select -expand ApplicationTypeVersion
获取服务清单版本:
Get-ServiceFabricService -ApplicationName fabric:/MyApplication -ServiceName fabric:/MyApplication/MyStatefulService | Select -expand ServiceManifestVersion
答案 2 :(得分:0)
也许我误解了你的问题,但this.Context.CodePackageActivationContext.CodePackageVersion
呢?
答案 3 :(得分:0)
找出应用程序版本:
var fabricClient = new FabricClient();
var applicationTypeList = await fabricClient.QueryManager.GetApplicationTypeListAsync(
Context.CodePackageActivationContext.ApplicationTypeName);
var applicationType = applicationTypeList.FirstOrDefault();
var applicationVersion = applicationType?.ApplicationTypeVersion;