4

私がやろうとしているのは、そのtransformうちの1つがappSettings外部ファイルにあります:

これがexternal.configです

<?xml version="1.0"?>
    <appSettings>
    <add key="SomeKey" value="some value" />
    </appSettings>

Web.config

<?xml version="1.0"?>
    <configuration>
        <appSettings file="..\..\external.config">
            <add key="SomeKey1" value="some value 1" />
        </appSettings>
    </configuration>

Web.Debug.config

<?xml version="1.0"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        <appSettings>
            <add key="SomeKey" value="some changed value"xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
       </appSettings>
    </configuration>

適切にビルドした後configuration、私の例ではDebugこれだけがあります:

<?xml version="1.0"?>
    <configuration>
        <appSettings file="..\..\external.config">
            <add key="SomeKey1" value="some value 1" />
        </appSettings>
    </configuration>

ただし、次のようにする必要があります。

<?xml version="1.0"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        <appSettings>
            <add key="SomeKey1" value="some value 1" />
            <add key="SomeKey" value="some changed value"/>
       </appSettings>
    </configuration>

appSettings2つ以上の異なるもので共有しようとしましたproject1番目がWCF Service2番目ですASP.NET MVC 4 Application

編集:

これをに移動しようとしましfile attributeWeb.Debug.configが、うまくいきません。

質問は:

どうすればそのようなことを達成できますか?それは可能ですか?

4

1 に答える 1

1

面白い。私はあなたと同じ問題を抱えています。そこで、参考までに回避策をご紹介します。プロジェクト ファイルを開いてください - XXX.csproj、たとえば ISWB.Test.Unit.csproj

このようなセクションの下に追加

<!-- Rock Add here, 2015.03.19 enable the external config transformation -->
  <Target Name="BeforeCompile" Condition="Exists('ISWB.$(Configuration).config')">
    <!--Generate transformed app config in the intermediate directory-->
    <TransformXml Source="ISWB.config" Destination="$(IntermediateOutputPath)ISWB.config" Transform="ISWB.$(Configuration).config" />
    <!--Force build process to use the transformed configuration file from now on.-->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="ISWB.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)ISWB.config">
        <TargetPath>ISWB.config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>

  <Target Name="AfterCompile" Condition="Exists('app.$(Configuration).config')">
    <!--Generate transformed app config in the intermediate directory-->
    <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
    <!--Force build process to use the transformed configuration file from now on.-->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="app.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
        <TargetPath>$(TargetFileName).config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>

追加されたセクションに注意してください。テキスト エディターで cs プロジェクト ファイルに手動で追加する必要があります。ISWB を自分のものに置き換えてください。そして、それを保存します。

それはうまくいくはずです。楽しめ!

于 2015-03-19T06:24:57.987 に答える