DZone
Cloud Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Cloud Zone > Windows #Azure configuration transformations

Windows #Azure configuration transformations

Romiko Derbynew user avatar by
Romiko Derbynew
·
Feb. 10, 12 · Cloud Zone · Interview
Like (0)
Save
Tweet
3.36K Views

Join the DZone community and get the full member experience.

Join For Free

hi,

i needed to update the transformation today to support different csdef files for uat/test etc. i found myself forgetting the process, so i thought it would be a good idea to log the entries needed.

what i wanted was a way to disable new relic in our performance environment, since we do not have a license key.

since we use the azure tasks to run batch jobs before the worker role starts, it made sense that i create a task environment variable that my batch script can check and see if it should install new relic, e.g.

	if "%mystoryenv%" == "perf" goto :eof

so, in the above, my batch file startup.cmd will skip installing new relic if the environment variable is perf. however we need to set this value in the csdef file.

so we go to the base servicedefinition.csdef file and have this entry for it.

<sd:startup>
      <sd:task commandline="startup.cmd" executioncontext="elevated" tasktype="background">
        <sd:environment>
          <sd:variable name="emulated">
            <sd:roleinstancevalue xpath="/roleenvironment/deployment/@emulated" />
          </sd:variable>
          <sd:variable name="mystoryenv" value="dev" />
        </sd:environment>
      </sd:task>
    </sd:startup>

notice, that i have qualified all my csdef entries, this is important for transformations to occur (sd:)

ok, the next step is that we create a transformation file

https://gist.github.com/1777060

now, that we have this transform, we will need to edit the csproj file. please see below the parts added

item groups

<itemgroup>
<servicedefinition include="servicedefinition.csdef" />
<serviceconfiguration include="serviceconfiguration.cscfg" />
</itemgroup>
<itemgroup>
<environmentdefinition include="servicedefinition.uat.csdef">
<baseconfiguration>servicedefinition.csdef</baseconfiguration>
</environmentdefinition>
<environmentdefinition include="servicedefinition.perf.csdef">
<baseconfiguration>servicedefinition.csdef</baseconfiguration>
</environmentdefinition>
<environmentconfiguration include="serviceconfiguration.uat.cscfg">
<baseconfiguration>serviceconfiguration.cscfg</baseconfiguration>
</environmentconfiguration>
<environmentconfiguration include="serviceconfiguration.perf.cscfg">
<baseconfiguration>serviceconfiguration.cscfg</baseconfiguration>
</environmentconfiguration>
<none include="@(environmentconfiguration)" />
<none include="@(environmentdefinition)" />
</itemgroup>

notice i have the include at the bottom, so i can see these in visual studio. i also have transformations for cscfg files, hence the reason why you see them here smile

targets validation

<target name="validateservicefiles"
		inputs="@(environmentconfiguration);@(environmentconfiguration->'%(baseconfiguration)');@(environmentdefinition);@(environmentdefinition->'%(baseconfiguration)')"
		outputs="@(environmentconfiguration->'%(identity).transformed.cscfg');@(environmentdefinition->'%(identity).transformed.csdef')">

	<message text="validateservicefiles: transforming %(environmentconfiguration.baseconfiguration) to %(environmentconfiguration.identity).tmp via %(environmentconfiguration.identity)" />
	<transformxml source="%(environmentconfiguration.baseconfiguration)" transform="%(environmentconfiguration.identity)" destination="%(environmentconfiguration.identity).tmp" />
	<message text="validateservicefiles: transformation complete; starting validation" />

	<message text="validateservicefiles: transforming %(environmentdefinition.baseconfiguration) to %(environmentdefinition.identity).tmp via %(environmentdefinition.identity)" />
	<transformxml source="%(environmentdefinition.baseconfiguration)" transform="%(environmentdefinition.identity)" destination="%(environmentdefinition.identity).tmp" />
	<message text="validateservicefiles: transformation complete; starting validation" />

	<validateservicefiles servicedefinitionfile="@(servicedefinition)" serviceconfigurationfile="%(environmentconfiguration.identity).tmp" />
	<validateservicefiles servicedefinitionfile="%(environmentdefinition.identity).tmp" serviceconfigurationfile="@(serviceconfiguration)" />
	<message text="validateservicefiles: validation complete; renaming temporary file" />

	<move sourcefiles="%(environmentconfiguration.identity).tmp" destinationfiles="%(environmentconfiguration.identity).transformed.cscfg" />
	<move sourcefiles="%(environmentdefinition.identity).tmp" destinationfiles="%(environmentdefinition.identity).transformed.csdef" />
</target>

notice above i have them for both cscfg and csdef files!

move transforms to the app.publish folder for azure packaging

<target name="movetransformedenvironmentconfigurationxml" aftertargets="afterpackagecomputeservice" inputs="@(environmentconfiguration->'%(identity).transformed.cscfg')" outputs="@(environmentconfiguration->'$(outdir)app.publish\%(filename).cscfg')">
<move sourcefiles="@(environmentconfiguration->'%(identity).transformed.cscfg')" destinationfiles="@(environmentconfiguration->'$(outdir)app.publish\%(filename).cscfg')" />
<move sourcefiles="@(environmentdefinition->'%(identity).transformed.csdef')" destinationfiles="@(environmentdefinition->'$(outdir)app.publish\%(filename).csdef')" />
</target>

summary

so there you have it, you will now have csdef and cscfg files for different environments.

source: http://romikoderbynew.com/2012/02/09/windows-azure-configuration-transformations/

azure

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Screen Sharing in Java
  • No Code Expectations vs Reality
  • Introduction to JWT (Also JWS, JWE, JWA, JWK)
  • What Are Microservices?

Comments

Cloud Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo