2017年2月4日土曜日

Team Foundation Server2017(tfs2017)を使った継続的インテグレーションの進め(CI)

TFSを使ってConsoleApplication付きのパッケージを配布する際にパラメータを定義(parameters.xml)し、Deploy時に設定する方法。

■parameters.xmlのサンプル

<?xml version="1.0" encoding="utf-8" ?>
<parameters>
  <parameter name="WebService1 Endpoint Address"
    description="Please provide the endpoint address for the Web service that you want to call."
    defaultValue="http://contoso.com/WebService1.asmx" tags="">
  <parameterEntry
    kind="XmlFile"
    scope="obj\\Debug\\Package\\PackageTmp\\Web\.config$"
    match="//setting[@name='WebService1EndPoint']/value/text()" />
  </parameter>

  <parameter name="appSettings_hoge" description="ほげ">
    <parameterEntry
      kind="XmlFile"
      defaultValue="hoge"
      scope="\\Web.config$"
      match="//appSettings/add[@key='hoge']/@value" />
  </parameter>
  <parameter name="appSettings_foo" description="ふー">
    <parameterEntry
      kind="XmlFile"
      defaultValue="foo"
      scope="\\Web.config$"
      match="//appSettings/add[@key='foo']/@value" />
  </parameter>

  <!--動作した-->
    <parameter name="Web.config_appSettings_abeKey" description="デプロイテスト">
      <parameterEntry kind="XmlFile" defaultValue="UseDevelopmentStorage=true" scope="\\Web.config$" match="//appSettings/add[@key='abeKey']/@value" />
    </parameter>

  <!--成功した-->
  <parameter name="ConsoleApp_App.config_ConnectionString" description="デプロイテスト">
    <parameterEntry kind="XmlFile" defaultValue="hogehoge" scope="\\App_Data\\AbeConsoleApplicaition\\AbeConsoleApplication\.exe\.config$"
                    match="/configuration/connectionStrings/add[@name='AbeConsoleApplication.Properties.Settings.ConnectionSetting']/@connectionString" />
    <parameterEntry kind="XmlFile" defaultValue="hogehoge" scope="\\App_Data\\AbeConsoleApplicaition\\AbeConsoleApplication\.exe\.config$"
                    match="/configuration/connectionStrings/add[@name='AbeConsoleApplication.Properties.Settings.ConnectionSetting2']/@connectionString" />
  </parameter>

<!--成功した-->
  <parameter name="ConsoleApp_App.config_AbeSetting" description="デプロイテスト" defaultValue="aaa" tags="">
    <parameterEntry kind="XmlFile" scope="\\App_Data\\AbeConsoleApplicaition\\AbeConsoleApplication\.exe\.config$"
                    match="/configuration/applicationSettings/AbeConsoleApplication.Properties.Settings/setting[@name='AbeSetting']/value/text()" />
  </parameter>
</parameters>

■Web.config
<configuration>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-AbeWebApplication-20160414071328.mdf;Initial Catalog=aspnet-AbeWebApplication-20160414071328;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="abeKey" value="TestValue"/>
  </appSettings>


■App.config
<configuration>
    <connectionStrings>
        <add name="AbeConsoleApplication.Properties.Settings.ConnectionSetting"
            connectionString="Data Source=localhost;Initial Catalog=abedb;Persist Security Info=True;User ID=sa;Password={password}"
            providerName="System.Data.SqlClient" />
        <add name="AbeConsoleApplication.Properties.Settings.ConnectionSetting2"
            connectionString="Data Source=localhost;Initial Catalog=abedb;Persist Security Info=True;User ID=sa;Password={password}" />
    </connectionStrings>
  <applicationSettings>
        <AbeConsoleApplication.Properties.Settings>
              <setting name="AbeSetting" serializeAs="String">
                    <value>fugofugo</value>
              </setting>
        </AbeConsoleApplication.Properties.Settings>
    </applicationSettings>
</configuration>

■Deploy IIS AppのOverrride Parameters

name="IIS Web Application Name",value="HogeHoge"
name="DefaultConnection-Web.config Connection String",value="data source=serverName;initial catalog=abedb;user id=sa;password={password};MultipleActiveResultSets=True;App=EntityFramework"
name="Web.config_appSettings_abeKey",value="これが出れば成功"
name="ConsoleApp_App.config_ConnectionString",value="$(ConnectionStringOLAP)"
name="ConsoleApp_App.config_AbeSetting",value="これです。"


0 件のコメント:

コメントを投稿