Service Fabric默认发布配置文件(不是Local.xml) [英] Service Fabric Default Publish Profile other than Local.xml

查看:135
本文介绍了Service Fabric默认发布配置文件(不是Local.xml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司正在使用Service Fabric开发我们的新应用程序. 我们遇到的一个常见问题是,多个开发人员使用远程服务器上的队列,数据库和存储,并且每个人对此都有不同的配置,所有设置都存储在每个环境的ApplicationParameters文件中,对于Local开发,只有一个Local.5Node .xml.当我们获得这些文件的最新版本时,很常见的开发人员会签入其凭据并覆盖其他人.

Our company is developing our new applications using Service Fabric. A common problem we have, multiple developers use queues, databases, storages that are on remote servers, and each one has different configuration for this, all the settings are stored on ApplicationParameters file per environment, for Local development there is a single Local.5Node.xml. It is very common developers checkin their credentials and overwrite others when we get latest version of these files.

我正在尝试自定义ServiceFabric部署脚本"Deploy-FabricApplication.ps1",以根据记录的用户的Windows凭据使用自定义的PublishProfile.我可以实现更新部署文件的更新,当我们使用发布进行部署时,它工作得很好,但是似乎当我们按下F5(调试)时ServiceFabric的默认行为是使用特定的Local.5Node.xml应用程序参数覆盖了这些参数.

I'm trying to customize the ServiceFabric deployment script 'Deploy-FabricApplication.ps1' to use a custom PublishProfile depending on windows credentials of logged user. I can achieve that updating the deployment file, it works well when we deploy using the publish, but it seems that the default behavior of ServiceFabric when we hit F5(debug) is overwrite the parameters with a specific Local.5Node.xml application parameters.

我浏览了所有服务结构.ps1文件,但找不到该文件的定义位置.我猜这是在.targets文件中定义的,所以我不知道如何避免这种默认行为.

I explored all service fabric .ps1 files and couldn't find where this is defined. I guess this is defined on .targets file, so I don't know how can I avoid this default behaviour.

除了Local.5Node.xml之外,还有其他方法可以在本地开发计算机上使用自定义PublishProfiles吗?

Is there any other approach to use custom PublishProfiles on local development machines other than Local.5Node.xml?

推荐答案

我实际上只是在设置一些特定于团队的环境时遇到了这个问题.我从以下来源借来了信息:

I actually just ran into this with setting up some team specific environments. I borrowed information from the following sources:

  • Web Config Transformation
  • Replace String In File With MSBUILD

我根据不同团队的需要添加了多个参数文件.每个包含其特定的资源设置.

I added multiple parameters files based on what was needed for the different teams. Each one containing their specific resource settings.

我还添加了Local.1Node.Template.xml和Local.5Node.Template.xml.我什至从源代码管理中删除了Local.1Node.xml和Local.5Node.xml并将它们设置为忽略,同时将它们留在项目中,这样Visual Studio不会认为它们确实缺失. 1Node的内容(除了用5Node替换1Node之外,其他5Node相同)

I also added a Local.1Node.Template.xml and Local.5Node.Template.xml. I even removed the Local.1Node.xml and Local.5Node.xml from source control and set them up to be ignored while leaving them in the projects so that Visual Studio doesn't think they are truly missing. The contents of the 1Node (5Node is the same except for replacing 1Node with 5Node) are as follows:

<?xml version="1.0" encoding="utf-8"?>
<PublishProfile xmlns="http://schemas.microsoft.com/2015/05/fabrictools">
    <ClusterConnectionParameters />
    <ApplicationParameterFile Path="..\ApplicationParameters\Local.1Node.$(Configuration).xml" />
</PublishProfile>

然后我为Service Fabric项目编辑了sfproj文件,以包含以下MSBuild任务和目标:

I then edited the sfproj file for the Service Fabric project to contain the following MSBuild Task and Target:

<UsingTask TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
        <InputFilename ParameterType="System.String" Required="true" />
        <OutputFilename ParameterType="System.String" Required="true" />
        <MatchExpression ParameterType="System.String" Required="true" />
        <ReplacementText ParameterType="System.String" Required="true" />
    </ParameterGroup>
    <Task>
        <Reference Include="System.Core" />
        <Using Namespace="System" />
        <Using Namespace="System.IO" />
        <Using Namespace="System.Text.RegularExpressions" />
        <Code Type="Fragment" Language="cs">
            <![CDATA[
                File.WriteAllText(
                    OutputFilename,
                    Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
                );
            ]]>
        </Code>
    </Task>
</UsingTask>
<Target Name="UpdateProfile" BeforeTargets="UpdateServiceFabricApplicationManifest">
    <ReplaceFileText InputFilename="PublishProfiles\Local.1Node.Template.xml" OutputFilename="PublishProfiles\Local.1Node.xml" MatchExpression="\$\(Configuration\)" ReplacementText="$(Configuration)" />
    <ReplaceFileText InputFilename="PublishProfiles\Local.5Node.Template.xml" OutputFilename="PublishProfiles\Local.5Node.xml" MatchExpression="\$\(Configuration\)" ReplacementText="$(Configuration)" />
</Target>

最后一步是为团队设置不同的构建配置.我根据Service Fabric Service项目和Service Fabric Host项目中的Debug配置通过FT6-Debug创建了FT1-Debug.我不理会所有其他项目.

The final step was to setup the different Build Configurations for the teams. I created a FT1-Debug through FT6-Debug based on the Debug configuration in the Service Fabric Service project and the Service Fabric Host project. I left all of my other projects alone.

这时,不同团队中的每个人都可以使用他们正在工作的集群的正确配置在本地调试,只需更改构建配置并按F5即可进行调试.

At this point everyone on the different teams can debug locally with the correct configuration for the cluster they are doing work in just by changing the Build Configuration and pressing F5 to debug.

这篇关于Service Fabric默认发布配置文件(不是Local.xml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆