Giter VIP home page Giter VIP logo

xdttransformconfigonbuild's Introduction

Using Web.config Transformation Syntax in Web Project Deployment for Web Project Build, in Class Library and in Windows Applications

A transform file is an XML file that specifies how the Web.config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix. The XML-Document-Transform namespace defines two attributes: Locator and Transform. The Locator attribute specifies the Web.config element or set of elements that you want to change in some way. The Transform attribute specifies what you want to do to the elements that the Locator attribute finds.

To use trasformation with build in web, class library and windows application projects

  • Unload the project
  • Edit the project file *.csporj
  • Append these line at the end of the file and before the </project> tag closing
    • For web projects
  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="ApplyWebConfigTransform" Condition="Exists('Web.$(Configuration).config')">
    <!-- Importance="High" for messages mean they show up in VS output window. -->
    <Message Importance="High" Text="Clearing read-only flag..." />
    <!-- TFS insists on marking all files in source control as read-only... -->
    <Exec Command="%SystemRoot%\system32\attrib -r Web.config" />
    <Message Importance="High" Text="Running configuration transform: $(Configuration) =&gt; Web.$(Configuration).config" />
    <TransformXml Source="Web.config" Transform="Web.$(Configuration).Config" Destination="web.config" />
  </Target>
  <Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">
    <CallTarget Targets="ApplyWebConfigTransform" />
  </Target>
  • For windows and class library projects
  <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="ApplyAppConfigTransform" Condition="Exists('App.$(Configuration).config')">
    <!-- Importance="High" for messages mean they show up in VS output window. -->
    <Message Importance="High" Text="Clearing read-only flag..." />
    <!-- TFS insists on marking all files in source control as read-only... -->
    <Exec Command="%SystemRoot%\system32\attrib -r App.config" />
    <Message Importance="High" Text="Running configuration transform: $(Configuration) =&gt; App.$(Configuration).config" />
    <TransformXml Source="App.config" Transform="App.$(Configuration).Config" Destination="App.config" />
  </Target>
  <Target Name="BeforeBuild">
    <CallTarget Targets="ApplyAppConfigTransform" />
  </Target>
  1. Save the project then reload
  2. Add the transformation attributes to the configuration transform files and build

Check the sample web, class library and console projects

For more details and transformation attributes and locators check: For more details and transformation attributes and locators check here

xdttransformconfigonbuild's People

Contributors

saiedbasha avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.