【发布时间】:2022-01-17 01:16:25
【问题描述】:
我想知道是否有人可以帮助我解决一些关于 Azure Service Fabric 的 ServiceManifest.xml 和 ApplicationManifest.xml 文件的问题。
背景
我正在使用依赖于 Azure Service Fabric 技术的 C# 多服务应用程序。我们为整个应用程序使用ApplicationManifest.xml 文件,为每个单独的服务使用ServiceManifest.xml 文件。我们的 ServiceManifest 遵循以下模板:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="MyServiceName.ConfigurationServicePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in RegisterServiceType call in Program.cs. -->
<StatelessServiceType ServiceTypeName="MyServiceName.Configuration" >
<PlacementConstraints>requestManagerAllowed==true</PlacementConstraints>
</StatelessServiceType>
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>MyCompanyName.MyServiceName.Configuration.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/>
</EnvironmentVariables>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0"/>
</ServiceManifest>
我们的服务(以及整个解决方案)最近被重新命名为我们必须部署到的新环境,同时仍部署到旧环境。我们已经编辑了所有 .csproj 文件,使其具有两个不同的程序集名称,具体取决于我们所针对的构建配置,以便我们可以为新旧环境构建和发布二进制文件。
例如,我们的应用程序中有一个配置服务。使用旧的构建配置构建时,配置服务的 exe 将命名为如下OldCompanyName.OldServiceName.Configuration.exe
使用新的构建配置构建时,名称会发生变化,看起来像NewCompanyName.NewServiceName.Configuration.exe
问题
问题是我们仍然需要能够同时部署到新旧环境。在尝试将我们的服务部署到新环境时,Service Fabric 使用配置服务的ServiceManifest.xml 来确定它需要找到OldCompanyName.OldServiceName.Configuration.exe 可执行文件作为该服务的入口点。但是,我们的解决方案必须使用新的构建配置来构建,所以所有的 exe 和 dll 都按照新约定 NewCompanyName.NewServiceName.Configuration.exe 命名。
由于找不到服务的入口点,Service Fabric 抛出如下异常:
The EntryPoint OldCompanyName.OldServiceName.Configuration.exe is not found.\r\nFileName: D:\\..\\..\\AppType\\..\\OldCompanyName.OldServiceName.ConfigurationServicePkg\\ServiceManifest.xml
我的问题
ServiceManifest.xml 是否支持根据使用的构建配置有两个单独的 ServiceManifest?举个例子,我的第一个想法是这样的(非常粗略的伪代码):
<?xml version="1.0" encoding="utf-8"?>
<!-- IF using old build configuration -->
<ServiceManifest Name="OldServiceName.ConfigurationServicePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in RegisterServiceType call in Program.cs. -->
<StatelessServiceType ServiceTypeName="OldServiceName.Configuration" >
<PlacementConstraints>requestManagerAllowed==true</PlacementConstraints>
</StatelessServiceType>
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>OldCompanyName.OldServiceName.Configuration.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/>
</EnvironmentVariables>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0"/>
</ServiceManifest>
<!-- If using NEW build configuration -->
<ServiceManifest Name="NewServiceName.ConfigurationServicePkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in RegisterServiceType call in Program.cs. -->
<StatelessServiceType ServiceTypeName="NewServiceName.Configuration" >
<PlacementConstraints>requestManagerAllowed==true</PlacementConstraints>
</StatelessServiceType>
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>NewCompanyName.NewServiceName.Configuration.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/>
</EnvironmentVariables>
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0"/>
</ServiceManifest>
基本上,我只需要一些方法让现有的ServiceManifest.xml 文件根据正在使用的构建配置(我们正在部署的环境)有条件地定位不同命名的入口点。对于如何实现这一点有什么想法吗?
【问题讨论】:
标签: c# xml azure-service-fabric service-fabric-stateless