Configuring a Free version of your WP8 App!

I recently decided to release a Free version of my app SpeechJammer, and I wanted to share some of the methods I used in order to create a ‘Free’ configuration of my existing project, as I think it may be helpful for other Windows Phone developers.

1. Create “Free” Debug and Release configurations of your project.

Open the Configuration Manager in Visual Studio by selecting ‘Configuration Manager’ in the Solution Configuration drop-down list. Then click on the Configuration drop-down and select ‘<New>’. Create new “Free Debug” and “Free Release” configurations and copy from the existing Debug and Release configurations respectively.

2. Define a FREE_VERSION conditional compilation symbol.

Right click on your project file and open the Properties window. Select the new ‘Free Debug’ configuration from the Configuration drop-down, then open the Build tab. Find the Conditional compilation symbols and append “;FREE_VERSION” to the end of the list. Rinse and repeat for the ‘Free Release’ configuration.

You can now have certain portions of your code for just the Free version, or just the Paid version. In the code sample below I’m setting up an ad control for the Free Version only. (Side note, I’m using the AdRotator control for the free version of my app and I would highly recommend it!)

public MainPage() { #if FREE_VERSION AdRotator.AutoStartAds = true; AdRotator.Visibility = Visibility.Visible; #else AdRotator.Visibility = Visibility.Collapsed; #endif } 1 2 3 4 5 6 7 8 9 public MainPage ( ) { #if FREE_VERSION AdRotator . AutoStartAds = true ; AdRotator . Visibility = Visibility . Visible ; #else AdRotator . Visibility = Visibility . Collapsed ; #endif }

3. Create a Free and Paid version of your WMAppManifest.xml

For this next part you need edit the .csproj file by hand. So unload your project. And then right-click on it and choose ‘Edit <your project>.csproj’. In the text editor find the lines that reference your WMAppManifest.xml file, and insert a few new lines:

<ItemGroup> <None Include="PropertiesAppManifest.xml" /> <None Include="PropertiesWMAppManifest.xml"> <SubType>Designer</SubType> </None> <None Include="PropertiesFreeWMAppManifest.xml"> <SubType>Designer</SubType> </None> <None Include="PropertiesPaidWMAppManifest.xml"> <SubType>Designer</SubType> </None> </ItemGroup> 1 2 3 4 5 6 7 8 9 10 11 12 < ItemGroup > < None Include = "PropertiesAppManifest.xml" / > < None Include = "PropertiesWMAppManifest.xml" > < SubType > Designer < / SubType > < / None > < None Include = "PropertiesFreeWMAppManifest.xml" > < SubType > Designer < / SubType > < / None > < None Include = "PropertiesPaidWMAppManifest.xml" > < SubType > Designer < / SubType > < / None > < / ItemGroup >

Before you reload your project, you need to actually go and create those files! Navigate to your Properties folder, create the ‘Free’ and ‘Paid’ directories, and just paste a copy of your existing WMAppManifest.xml file into each folder. Now go back to Visual Studio and reload that project.

In your project file you should now see the Free and Paid WMAppManifest files. For my Free version I changed the app name to “SpeechJammer Free” and created a new GUID for the Product ID. You can create a new GUID by going to the Tools menu and selecting Create Guid, or by navigating to C:Program Files (x86)Microsoft Visual Studio 11.0Common7Toolsguidgen.exe. This step is extremely important as the ProductID is how your phone identifies the apps installed on your phone. If you try to test Free and Paid versions of your app that use the same ProductID GUID they will just overwrite each other.

The last part of creating these new WMAppManifest.xml files is getting them into your XAP file. To do that go back to your projects properties, and go to the Build Events tab. You can insert the following copy commands into the Pre-build event commands in order to get Visual Studio to copy your new WMAppManifest.xml files:

if "$(ConfigurationName)" == "Free Debug" copy "$(ProjectDir)PropertiesFreeWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml" if "$(ConfigurationName)" == "Free Release" copy "$(ProjectDir)PropertiesFreeWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml" if "$(ConfigurationName)" == "Debug" copy "$(ProjectDir)PropertiesPaidWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml" if "$(ConfigurationName)" == "Release" copy "$(ProjectDir)PropertiesPaidWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml" 1 2 3 4 if "$(ConfigurationName)" == "Free Debug" copy "$(ProjectDir)PropertiesFreeWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml" if "$(ConfigurationName)" == "Free Release" copy "$(ProjectDir)PropertiesFreeWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml" if "$(ConfigurationName)" == "Debug" copy "$(ProjectDir)PropertiesPaidWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml" if "$(ConfigurationName)" == "Release" copy "$(ProjectDir)PropertiesPaidWMAppManifest.xml" "$(ProjectDir)PropertiesWMAppManifest.xml"

And that should do it! Please let me know if this post has been helpful in the comments!