Convert app.config for 3 different conditions

I need to convert the app.config file using msbuild. I can convert the file if it is called app.DEBUG.config or app.Release.config, but I cannot if I add one called app.PROD.config.

Using regular XDT conversions, msbuild will recognize different web.config files if I select a different PublishProfile

 msbuild path.to.project.csproj Configuration=Release PublishProfile=DEV

App.config does not seem to work with the same setting. I can always create a specific build configuration for installing DEV.config, but it seems useless to have a separate build confirmation for one application. The hacker way to do this is to simply copy the correct app.config file for the POST-BUILD environment.

I tried using the SlowCheetah plugin, but it only seems to convert the default DEBUG and RELEASE configuration files, which is not suitable since I have more than two environments. If I really use this incorrectly, tell me which parameter I should pass to msbuild in order to select my .DEV.config application.

The expected result will be that msbuild will convert app.config according to the conversion configured as app.DEV.config or the one configured for app.PROD.config. I would expect that there is a parameter that I can pass to msbuild that will allow me to use the Release configuration, but convert with a different name for each environment.

+4
3

, :

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- This target will run right before you run your app in Visual Studio -->
  <Target Name="UpdateWebConfigBeforeRun" BeforeTargets="Build">
    <Message Text="Configuration: $(Configuration) update from web.template.$(Configuration).config"/>
    <TransformXml Source="web.template.config"
              Transform="web.template.$(Configuration).config"
              Destination="web.config" />
    </Target>

  <!-- Exclude the config template files from the created package -->
  <Target Name="ExcludeCustomConfigTransformFiles" BeforeTargets="ExcludeFilesFromPackage">
    <ItemGroup>
      <ExcludeFromPackageFiles Include="web.template.config;web.template.*.config"/>
    </ItemGroup>
    <Message Text="ExcludeFromPackageFiles: @(ExcludeFromPackageFiles)" Importance="high"/>
  </Target>
</Project>

:

web.template.config
    - web.template.debug.config
    - web.template.production.config
    - web.template.release.config etc

.. , app. web.

+1

, , , .

, DEBUG RELEASE ( , ). web.config . app.config SlowCheetah Visual Studio , web.config, app.config. RELEASE system.web.

- (, QA, PROD). , .. web.config MSDEPLOY - IIS. app.config , . , WIX.

, , , . , : http://philippetruche.wordpress.com/2012/07/11/deploying-web-applications-to-multiple-environments-using-microsoft-web-deploy/

WIX , Windows Multi-Environment Visual Studio 2012 Wix.

+6

App.config

, , . - appSettings . .

App.config:

<?xml version="1.0" encoding="utf-8" ?><configuration>  <appSettings>    <add key="FirstName" value="Gunnar"/>  </appSettings></configuration>

App.Release.config

<?xml version="1.0"?><configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  <appSettings>    <add key="LastName" value="Peipman" xdt:Transform="Insert"/>  </appSettings></configuration>

:

<?xml version="1.0" encoding="utf-8" ?><configuration>  <appSettings>    <add key="FirstName" value="Gunnar"/>    <add key="LastName" value="Peipman"/>  </appSettings></configuration>

App.config

, .

  • App.config App.Release.config .
  • .
  • " a > ".
  • XML , , .
  • :

    <ProjectConfigFileName>App.Config</ProjectConfigFileName>
    
  • <ItemGroup>, App.Config(<None Include="App.Config" />), App.Config node:

    <None Include="App.Release.config"> 
        <DependentUpon>App.Config</DependentUpon>
    </None>
    
  • <Import Project= node :

    <Import Project="$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets" Condition="'$(VSToolsPath)' != ''" />
    <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" Condition="false" />
    
  • , ,    :

    <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
    <Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
      <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
      <ItemGroup>
        <AppConfigWithTargetPath Remove="app.config" />
        <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
          <TargetPath>$(TargetFileName).config</TargetPath>
        </AppConfigWithTargetPath>
        <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
          <TargetPath>$(TargetName).vshost$(TargetExt).config</TargetPath>
        </AppConfigWithTargetPath>
      </ItemGroup>
    </Target>
    
  • , .

When you reload the project, Visual Studio may ask you about some changes to the file, so all versions of Visual Studio 2010 can use your project file until now without any changes. Agree to this because then you have no dependencies on the versions of Visual Studio.

+1
source

All Articles