The Fastest Way to Switch Free/Paid and NoDo/Mango App Build in Visual Studio

Oct 1, 2011

Edit: Added NoDo/Mango switching as well. Simplified changes to .csproj files

How would you like to be able to switch from Free/Paid and NoDo/Mango  for your Windows Phone 7 projects in VS?

image   image

Yes! This will switch my Fantasia Painter app from Paid to Free, and it’s just a build configuration change.

I’ve been using it for the past 6 months or so. Here’s how to do it:

  1. Open Configuration Manager and add a “Free – Release” and “Free – Debug”. Add the Mango configurations above if needed.
  2. Create a Manifest/Free and Manifest/Paid folders in your project. If needed, duplicate these for Mango/NoDo to get 4 total!
  3. Copy the WMAppManifest.xml from Properties to the two folders you just created. The build action for the new files is None and Copy is Don’t Copy (from the item properties window)

image

4. Edit the free WMAppManifest to contain the GUID (Product ID) of your free version. Also change the Title and other fields in the XML as needed

5. Create a Pre-build event command line (from project properties) to copy the manifests based on the build configuration name:

if "$(ConfigurationName)" == "Free - Release" copy "$(ProjectDir)\Manifest\NoDo\Free\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"
if "$(ConfigurationName)" == "Free - Debug" copy "$(ProjectDir)\Manifest\NoDo\Free\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"
if "$(ConfigurationName)" == "Release" copy "$(ProjectDir)\Manifest\NoDo\Paid\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"
if "$(ConfigurationName)" == "Debug" copy "$(ProjectDir)\Manifest\NoDo\Paid\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"
if "$(ConfigurationName)" == "Mango Free - Release" copy "$(ProjectDir)\Manifest\Free\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"
if "$(ConfigurationName)" == "Mango Free - Debug" copy "$(ProjectDir)\Manifest\Free\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"
if "$(ConfigurationName)" == "Mango Release" copy "$(ProjectDir)\Manifest\Paid\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"
if "$(ConfigurationName)" == "Mango Debug" copy "$(ProjectDir)\Manifest\Paid\WMAppManifest.xml" "$(ProjectDir)\Properties\WMAppManifest.xml"

image

6. If you’re using the AdControl or other DLLs that are different between Free and Paid, edit the .csproj file to conditionally include them like so:

<ItemGroup Condition=" $(Configuration.Contains('Free'))">
  <Reference Include="Microsoft.Advertising.Mobile.UI">
    <HintPath>C:\Program Files\Microsoft SDKs\Advertising for Phone\Microsoft.Advertising.Mobile.UI.dll</HintPath>
  </Reference>
</ItemGroup>

7. You can also define a conditional variable in project properties FREE_WITH_ADS and then use it from the source file using #if FREE_WITH_ADS. Similarly, define a MANGO variable for Mango so you can do #if MANGO Smile

 

This concept naturally extends to NoDo/Mango switching. Just make sure to have 4 manifest files and have the word “Mango” in each of the solution/project configurations. Then change the .csproj like so:

<TargetFrameworkProfile Condition=" $(Configuration.Contains('Mango')) ">WindowsPhone71</TargetFrameworkProfile>
<TargetFrameworkProfile Condition=" !$(Configuration.Contains('Mango')) ">WindowsPhone</TargetFrameworkProfile>

Make sure to keep NoDo users happy by providing them with NoDo updates! A lot of people rarely update their phone (just search about the % of iPhone users that updated to the latest version online.) It’s very important to keep your app NoDo-ish and Mango-ish in my opinion.

Hope that helps! Please comment!

blog comments powered by Disqus

nokola.com | Terms | Log in

Recent

About the author

Happy & enjoying life. Software enthusiast.
The opinions I express here and on nokola.com are mine and not my employeer's (Microsoft).
This is the official blog of nokola.com. You can find Silverlight samples, coding stuff, and hopefully other interesting things here.