This is a mirror of official site: http://jasper-net.blogspot.com/

Using Custom Web.config Transformations in MSBUILD

| Sunday, June 24, 2012
Web.config transformations have been around for a while now, and a lot of developers use them in their staple day-to-day environment deployment strategies – hell, Scott Hanselman was spouting about them way back in the beginning on 2010 with his “Web Deployment Made Awesome: If you’re using XCOPY, you’re doing it wrong” post. As usual though, one size does not fit all – and in the case of Continuous Integration fans out there that may have specific build-configuration-based build and deployment scenarios (such as myself), there is the need to have finer grained control over the Web.config transformation process. If this sounds like you, then this post is aimed to deliver.

What a second… what the hell are “Web.config Transforms”?

ASP.net has had a few features that that been around for what seems like forever when it comes to abstracting away or alternating between different configuration data for your website (i’m talking about configSource functionality mostly). The features were very minimal and usually created a less-than-ideal solution for developers working on big websites in multiple environments. With the advent of Visual Studio 2010 Microsoft kindly helped us all out by taking note that “hey maybe not all websites are being built for a single server with a single configuration”… Smart guys. They created web.config transformations to help deal with this problem and Jokes aside, the feature is actually pretty cool and allows you to write a base web.config file as you normally would and then transform it for each of your environments.

Your base web.config:

<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="ExampleApplicationSetting" value="Value being replaced by Transform"/>
    </appSettings>
    <connectionStrings>
        <add name="MyConnectionString" connectionString="..." providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true">
        </compilation>
    </system.web>
</configuration>

Your web.config transform (note the change to my connection string, my custom errors and my compilation mode):

<?xml version="1.0"?>
    <appSettings>
        <add key="ExampleApplicationSetting"
                 xdt:Transform="SetAttributes(value)"
                 xdt:Locator="Condition(@key='ExampleApplicationSetting')"
                 value="The new value to replace after transform"/>
    </appSettings>
    <connectionStrings>
        <add name="MySolutionDatabase" xdt:Transform="Replace" xdt:Locator="Condition(@name='MySolutionDatabase')"
                 connectionString="... My New Connection String ..." providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <customErrors xdt:Transform="Replace" mode="RemoteOnly" />
        <compilation xdt:Transform="SetAttributes(debug)" debug="false" />
    </system.web>
</configuration>

Read more: DZone
QR: Inline image 1

Posted via email from Jasper-net

6 comments:

Anonymous said...

The yearly predictions and free matchmaking make person aware about his or her strengths, abilities and capabilities of the year which he can maneuver according to aims and ambitions., encryption ipsec. In other words, it is your definite weapon to win the game. Give what customers and tech savvy users of today likea website that is well deigned, informative, unique, backed with latest developments and is above all user friendly. internet unblock software. This is because of the fact that the procurement of the ideal tailormade product demands strict inspection to ensure proper comprehension, analysis and precise execution of thoughts into the final product. vpn 1 secureclient adapter

Anonymous said...

You probably know that laptops and notebooks have different instructions for troubleshooting. vpn russian servers. Certain types of ovarian cysts however might exhibit various symptoms in women and ovarian pain might be one obvious symptom of all. vpn network hamachi

Anonymous said...

Ask friends who own businesses. He is a dedicated and devoted professional who knows how to pick the gainers and is there to help you make money. adsl sl2 141 i treiber. It’s often not a question of whether to spend or not. The key is to make your message jump right out of your postcard so that it can grab attention., private studio flats. However, posting online classified ads is not a guarantee for success. free online account access

Anonymous said...

Appliances invariably add to the quality of our life style and particularly appliances like air conditioners and refrigerators stand exclusively important in terms of health. Superb for air shows, nature trips and an excellent choice when visiting the race track or watching other spectator sports., server reportservice asmx. If they can cut down the cost on their local cable company, they are then able to save hundreds possibly even thousands of dollars per year. meg adsl

Anonymous said...

A normal man may have been taken and pulled apart, but his father taught him how to kill a bear and to protect himself. In another site that provides answers online with pay. access city internet kansas. You love horses and want to learn more and to be the best at equestrian. Overall, the watch is highly appealing., natural selection server commands. Luxury tended camps is a must do, these are permanent tented establishments, an accommodation tent will come with en suite private bathroom with flash toilets, hot and cold showers, a queen size bed, lamps and a comfortable verandah some come with hammocks for that afternoon siesta, most verandas will overlook the plains or a waterhole where wildlife visits occasionally. http adsl libero it

Anonymous said...

Bank holidays are very important as every bank have lots of task to sum up in minimum time. Use builtin power management on your portable device., wdk virtual. The health insurance maternity helps in protecting the future of the child and the happiness of the parent. collagen network