2016-04-21 30 views
1

当我添加一个新的演员,以我的服务Fabric项目,该服务自动,因为我们有UpdateServiceFabricManifestEnabled设置为true添加到我的ApplicationManifest.xmlServiceManifest.xml文件。对于某些项目,我们需要服务具有PlacementConstraints,以便将它们部署到适当的节点。如何自定义我的服务清单文件的创建?

如何挂钩到此过程中,以便我可以指定PlacementConstraints而不必记住编辑任何清单文件?

+0

放置约束是服务清单的一部分。你需要在应用程序清单中编辑什么? –

+0

我不知道我知道如何回答@MattThalman :)我没有意识到PlacementConstraints出现在ServiceManifest.xml文件中(仍然有很多)。所以我相信我的问题应该是询问ServiceManifest而不是ApplicationManifest。但是,当我将它们添加到项目的ServiceManifest中时,构建不会将它们包含在ApplicationManifest中。 –

+0

不在应用清单中包含_what_?放置限制?他们不应该在应用程序清单中。我不确定我是否明白问题所在。 –

回答

1

服务清单文件被作为构建的一部分自动填充了actor参数类型。有一个MSBuild目标在内置的“Build”目标之后运行,它执行此操作。你可以使用你自己的逻辑,在这之后运行。在该逻辑中,您可以对服务清单文件进行任何必要的更改。以下示例确保将放置约束添加到服务清单文件中的所有服务类型。它使用内联的MSBuild任务,但您可以将其重写为包含在已编译的程序集或任何您想要执行的任务中。

该样品应放置在你的演员的服务项目中的文件的末尾:

<UsingTask TaskName="EnsurePlacementConstraints" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> 
    <ParameterGroup> 
    <ServiceManifestPath ParameterType="System.String" Required="true" /> 
    </ParameterGroup> 
    <Task> 
    <Reference Include="System.Xml" /> 
    <Reference Include="System.Xml.Linq" /> 
    <Using Namespace="System.Xml.Linq" /> 
    <Code Type="Fragment" Language="cs"> 
    <![CDATA[ 
const string FabricNamespace = "http://schemas.microsoft.com/2011/01/fabric"; 
XDocument serviceManifest = XDocument.Load(ServiceManifestPath); 
IEnumerable<XElement> serviceTypes = serviceManifest.Root.Element(XName.Get("ServiceTypes", FabricNamespace)).Elements(); 
bool changesMade = false; 
foreach (XElement serviceType in serviceTypes) 
{ 
    XName placementConstraintsName = XName.Get("PlacementConstraints", FabricNamespace); 
    if (serviceType.Element(placementConstraintsName) == null) 
    { 
    XElement placementConstraints = new XElement(placementConstraintsName); 
    placementConstraints.Value = "(add your contraints here)"; 
    serviceType.AddFirst(placementConstraints); 
    changesMade = true; 
    } 
} 

if (changesMade) 
{ 
    serviceManifest.Save(ServiceManifestPath); 
} 
    ]]> 
    </Code> 
    </Task> 
</UsingTask> 

<Target Name="EnsurePlacementConstraints" AfterTargets="Build"> 
    <EnsurePlacementConstraints ServiceManifestPath="$(MSBuildThisFileDirectory)\PackageRoot\ServiceManifest.xml" /> 
</Target> 
相关问题