我想知道是否有人可以幫助我解決有關 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檔案根據正在使用的構建配置(我們部署到哪個環境)有條件地定位不同命名的入口點。關于如何實作這一目標的任何想法?
uj5u.com熱心網友回復:
如果您正在使用管道(如管道功能 Azure DevOps),您可以使用標記生成器來替換使用變數或變陣列的不同環境的占位符字串。
您將創建一個帶有分隔占位符(像這樣{{key}})的服務清單模板,將它們替換為您正在運行的特定構建(舊的或新的),然后構建包。
模板如下所示:
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>{{companyname}}.Configuration.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
</CodePackage>
創建名為“companyname”的 Azure DevOps 變數,值為“NewCompanyName.NewServiceName”。
標記化后,檔案將如下所示:
<!-- 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>
</CodePackage>
uj5u.com熱心網友回復:
在您的服務專案中添加第二個服務清單檔案(具有您需要的所有更改的不同名稱)。然后編輯服務專案檔案:
<ItemGroup Condition="'$(Configuration)'=='Config2'">
<None Remove="PackageRoot\ServiceManifest.xml" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Config1'">
<None Remove="PackageRoot\OtherServiceManifest.xml" />
</ItemGroup>
在服務結構應用程式專案中,添加第二個應用程式清單檔案(將參考其他服務清單)。然后編輯專案檔案:
<ItemGroup Condition="'$(Configuration)'=='Config1'">
<None Include="ApplicationPackageRoot\ApplicationManifest.xml" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Config2'">
<None Include="ApplicationPackageRoot\OtherApplicationManifest.xml" />
</ItemGroup>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/383957.html
標籤:C# xml azure-service-fabric 服务结构无状态
