12

私の継続的インテグレーションサーバー(TeamCity)は、ビルド時にアプリのすべての単体テストを実行するように構成されています。これらのテストを実行する前に、いくつかのappSettingsを変更して、CIサーバーで有効にする必要があります。Visual Studioで提供される展開プロジェクトを使用して、Webプロジェクトで同様のことを実現しています。テストプロジェクトでも同じことができますか?

ありがとう、ゴンザロ

4

3 に答える 3

29

回避策により、 App.configファイルにWeb.config変換を使用することができます。

ビルドプロセスの適切な段階で、適切なMSBuildタスクを呼び出すだけです。
このコードスニペットをプロジェクトファイルに追加します。

<UsingTask
    TaskName="TransformXml"
    AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />

<Target Name="AfterCompile" Condition="exists('App.$(Configuration).config')">
    <!-- Generates the transformed App.config in the intermediate directory -->
    <TransformXml
        Source="App.config"
        Destination="$(IntermediateOutputPath)$(TargetFileName).config"
        Transform="App.$(Configuration).config" />
    <!-- Forces the build process to use the transformed configuration file -->
    <ItemGroup>
        <AppConfigWithTargetPath Remove="App.config"/>
        <AppConfigWithTargetPath
            Include="$(IntermediateOutputPath)$(TargetFileName).config">
            <TargetPath>$(TargetFileName).config</TargetPath>
        </AppConfigWithTargetPath>
    </ItemGroup>
</Target>

次に、変換を適用するビルド構成ごとに、プロジェクトにApp.configファイルを追加します。例えば:

<ItemGroup>
    <None Include="App.config" />
    <None Include="App.Release.config">
        <DependentUpon>App.config</DependentUpon>
    </None>
</ItemGroup>

関連リソース:

于 2011-02-23T13:25:58.210 に答える
7

web.configを変換するのと同じ方法でapp.configを変換するために使用できるVisualStudioaddを作成しました。アドインSlowCheetahは、 http: //visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5にあります。

ビルドサーバーでもこれを機能させる方法についてブログを投稿しました。

于 2012-01-30T08:44:39.370 に答える
6

テスト時に、構成ルックアップをラップし、インターフェースを抽出して、これをスタブ化することをお勧めします。

于 2011-02-23T13:04:30.937 に答える