如何在运行时获取执行的Service Fabric服务(和应用程序)版本?我尝试过上下文,但是StatefulServiceContext
和StatelessServiceContext
都没有提供该信息。
如何在运行时获取执行的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
,这与服务清单的版本不同ServiceManifestVersion
与CodePackageVersion
是一个很好的观点。因此,对于服务版本,为什么不使用Context.CodePackageActivationContext.GetServiceManifestVersion()
呢? - Sean FeldmanFabricClient
" - 客户端创建成本高吗? - Philip PittleGet-ServiceFabricApplication -ApplicationName fabric:/MyApplication | Select -expand ApplicationTypeVersion
获取服务清单版本:
Get-ServiceFabricService -ApplicationName fabric:/MyApplication -ServiceName fabric:/MyApplication/MyStatefulService | Select -expand ServiceManifestVersion
this.Context.CodePackageActivationContext.CodePackageVersion
怎么样?查找应用程序版本:
var fabricClient = new FabricClient();
var applicationTypeList = await fabricClient.QueryManager.GetApplicationTypeListAsync(
Context.CodePackageActivationContext.ApplicationTypeName);
var applicationType = applicationTypeList.FirstOrDefault();
var applicationVersion = applicationType?.ApplicationTypeVersion;