visual studio - Modifying WMAppManifest.xml based on Build Configuration -


i release distinct flavours of app , indicate in application name displayed on phone. far know silverlight phone apps name solely determined wmappmanifest.xml. therefore modify application title @ build time based on build configuration. suggestions?

you can bit of t4 templating , code generation (see http://msdn.microsoft.com/en-us/library/bb126445.aspx if don't know this.)

the following steps allow use different application title if using debug or release configuration.

take copy of wmappmanifest.xml , rename wmappmanifest-base.tt

change content of wmappmanifest-base.tt be

<#@ template language="c#" #><#@ output extension=".xml" #><?xml version="1.0"?> <deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" appplatformversion="7.0">   <app xmlns="" productid="{4c5315b6-4030-46c5-b5ea-17284d6af0c6}" title="<#= this.configuredapptitle #>" runtimetype="silverlight" version="1.0.0.0" genre="apps.normal"  author="windowsphoneapplication8 author" description="sample description" publisher="windowsphoneapplication8">     <iconpath isrelative="true" isresource="false">applicationicon.png</iconpath>     <capabilities>       <capability name="id_cap_identity_device"/>       <capability name="id_cap_networking"/>     </capabilities>     <tasks>       <defaulttask  name ="_default" navigationpage="mainpage.xaml"/>     </tasks>     <tokens>       <primarytoken tokenid="windowsphoneapplication8token" taskname="_default">         <templatetype5>           <backgroundimageuri isrelative="true" isresource="false">background.png</backgroundimageuri>           <count>0</count>           <title><#= this.configuredapptitle #></title>         </templatetype5>       </primarytoken>     </tokens>   </app> </deployment> <#+      string configuredapptitle = "myphoneapp"; #> 

(adjust capabilities, etc. appropriate.)

in same folder wmappmanifest-base.tt create file called debug.wmappmanifest.tt following contents:

<#   configuredapptitle = "mydebugapp"; #><#@ include file="wmappmanifest-base.tt" #> 

now create file called release.wmappmanifest.tt following contents:

<#   configuredapptitle = "myreleaseapp"; #><#@ include file="wmappmanifest-base.tt" #> 

create file called copyifnewer.bat in root of project. give following contents:

echo comparing: %1 %2  if not exist %1 goto file1notfound if not exist %2 goto file2notfound  fc %1 %2  if %errorlevel%==0 goto nocopy  echo files not same.  copying %1 on %2 copy %1 %2 /y & goto end  :nocopy echo files same.  did nothing goto end  :file1notfound echo %1 not found. goto end  :file2notfound copy %1 %2 /y goto end  :end 

in project properties add pre-build command:

"$(projectdir)\copyifnewer.bat" "$(projectdir)properties\$(configurationname).wmappmanifest.xml" "$(projectdir)properties\wmappmanifest.xml" 

now can adjust values in debug & release files alter titles wish.

if have other configurations create appropriately named files (with same contents debug.*.tt) , they'll picked automatically.

note when testing, if install app 1 name (in emulator or phone) you'll have uninstall see name change reflected in application list.

note self: must blog this. (it's powerful hard work out how first time.)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -