Web.config style conversions for App.config files for C # console applications?

My team loves publishing profiles. We have several test environments in which we work, and using Web.config transformations, we can replace the machine names in each environment, configuration parameters, etc., which will greatly simplify the assembly / deployment / testing process.

For example:

Web.config
    Web.dev.config
    Web.int.config
    Web.prod.config

However, we do have some test applications that we use to get into our web services implemented as console applications. We would like to be able to do the same types of conversions in these configuration files so that we can reduce the manual testing work involved in manually editing configuration files during assembly assembly.

Essentially, we want:

App.config
    App.dev.config
    App.int.config
    App.prod.config

, -:

Properties
    PublishProfiles
        dev.pubxml
        int.pubxml
        prod.pubxml

, , - - MSBuild, .

, --?

+4
5

app.configs :

2013. . .

. App.config. " ". , .

App.config:

<appSettings>
    <add key="key" value="some value" />   
</appSettings>

App.Release.Config:

<appSettings>
    <add key="same key which you have given in app.config" value="some new value" xdt:Transform="Replace" xdt:Locator="Match(key)" />   
 </appSettings>

, .

+7
+3

, :

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="BeforeBuild" Condition="">
    <Message Text="Transforming Configs files..." Importance="high" />
    <TransformXml Source="App_Data\config\appSettings.config" Transform="App_Data\config\appSettings.$(Configuration).config" Destination="App_Data\config\appSettings_temp.config" />
    <Copy SourceFiles="App_Data\config\appSettings_temp.config" DestinationFiles="App_Data\config\appSettings.config" OverwriteReadOnlyFiles="True" />
    <Delete Files="App_Data\config\\appSettings_temp.config" />
  </Target>

:

  • TransformXml UseTask (, Visual Studio)
  • . ( "", "", "" )
  • TransformXml .
  • . OverwriteReadOnlyFiles, TFS, , .
0

Azure WebJobs App.config , Visual Studio MSBuild .

Azure WebJobs .csproj :

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="Exists('App.$(configuration).config')">
    <Message Text="Transforming config files..." Importance="high" />
    <TransformXml Source="App.config" Transform="App.$(Configuration).config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" />
    <PropertyGroup>
      <AppConfig>$(IntermediateOutputPath)$(TargetFileName).config</AppConfig>
    </PropertyGroup>
    <ItemGroup>
        <AppConfigWithTargetPath Remove="App.config" />
        <AppConfigWithTargetPath Include="$(AppConfig)" Condition="'$(AppConfig)'!=''">
            <TargetPath>$(TargetFileName).config</TargetPath>
        </AppConfigWithTargetPath>
    </ItemGroup>
</Target>

, , App.config . Dhia Louhichi.

0

All Articles