StackPop Studios header image

Tutorial – Using Visual Studio Solution Configuration to Manage Free and Paid Game Versions

This tutorial details steps for easily managing different versions of your game in Visual Studio. We found this extremely useful while developing Chromatic since it greatly simplified management of our paid vs. our free version.

After the following steps are in place, you can use the Visual Studio solution configuration drop down as a single place to switch between paid and free versions and see your app’s title, tile image, and version-specific game logic change automatically.

One note is that this is proven to work well for Visual Studio Pro: Visual Studio express is designed to simplify solution configuration and therefore the options are not exposed as easily and may not behave the same. There’s a blog here you can reference to expose the solution configuration for VS Express.

To start, in VS navigate to Build->Configuration Manager. Under “Active solution configuration” drop-down, click “”:

For this example, we will name one version “Pro Version”, and choose to copy the settings from Release configuration:

Repeat the above steps to also create a “Lite version”:

Close the configuration manager. In Visual Studio, you should have a configuration manager drop-down in the task bar below the menu bar. This is where you can choose between the different solution configurations, and where you will now see the Pro and Lite versions we just added:

With the “Pro Version” configuration chosen, right click the project and go to properties. Choose the “Build” tab, and then add “PRO_VERSION” to the Conditional compilation symbols (note that these symbols are ‘;’-separated).

Switch to the “Lite Version” configuration using the configuration drop-down and add LITE_VERSION to the conditional compilation symbols:

What we’ve just done is given ourselves the ability to change in-app logic based on the configuration selected for the solution. Compilation conditionals aren’t the prettiest, but if you confine their use to a single utility file or similar you can easily do some nice things without too much ugliness. A simple example is as follows:

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        public static bool ProVersion
        {
            get
            {
#if PRO_VERSION
                return true;
#else
                return false;
#endif
            }
        }
  …

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            Color gameColor = ProVersion ? Color.Blue : Color.Red;
            GraphicsDevice.Clear(gameColor);

            base.Draw(gameTime);
        }
    }

All this example will do is change the background color based on the selected configuration, but the basics are there. Note that the compilation conditional check is wrapped inside a simple Boolean accessor: this is intentional to avoid having to have compilation conditional checks scattered throughout code. Did we mention compilation conditionals are ugly? :)

Our next step is to setup different app names based on solution config. Open AssemblyInfo.cs and set the existing AssemblyTitle and AssemblyProduct values to the following:

#if PRO_VERSION
[assembly: AssemblyTitle("Pro Version Game")]
[assembly: AssemblyProduct("Pro Version Game")]
#else
[assembly: AssemblyTitle("Lite Version Game")]
[assembly: AssemblyProduct("Lite Version Game")]
#endif

You’ll be happy you did this when it comes time to submit your paid and free games: without it both will have the exact same name! Note that AssemblyTitle is what actually controls the app name as it appears in the marketplace, but it is good practice to update AssemblyProduct to go with it.

Our final setup step is to enable a different tile title and image for each version. For this example, we’ll assume that we want our tiles to show up as follows:

Pro:

Lite:

Open the csproj up in notepad and move the and tags into both the “Pro Version” and “Lite Version” PropertyGroups, and then set each value to point to the specific tile images for each version and each value to the desired text:

Finally, we’ll create a static class to create convenient properties to determine what type of game the user is playing, with some included logic assuming that both Lite and trial-Pro version will have ads:

using Microsoft.Xna.Framework.GamerServices;

namespace VersionGame
{
    public static class GameConstants
    {
        /// <summary>
        /// Whether the app is Pro(Paid) or Lite(Free)
        /// </summary>
        public static bool PaidVersion
        {
            get
            {
#if PRO_VERSION
                return true;
#else
                return false;
#endif
            }
        }

        /// <summary>
        /// Only show Ads in the lite version and the trial version
        /// </summary>
        public static bool ShowAds
        {
            get
            {
#if PRO_VERSION
                return IsTrial;
#else
                return true;
#endif
            }
        }

        /// <summary>
        /// Whether this is a trial version (Pro/Trial) or not(Pro/Paid,Lite/Free)
        /// </summary>
        public static bool IsTrial
        {
            get
            {
#if PRO_VERSION
                // Guide.IsTrialMode is expensive, so cache it
                if (!isTrial.HasValue)
                {
                    isTrial = Guide.IsTrialMode;
                }

                return isTrial.Value;
#else
                return true;
#endif
            }
        }

#if PRO_VERSION
        /// <summary>
        /// Cached value for whether it is a trial or not
        /// </summary>
        private static bool? isTrial;
#endif
    }
}

At this point we can sprinkle IF checks throughout the code to do different things depending on whether the user is playing the Paid, Trial, or Free version of your game.

For our example we’ll add some very simple drawing logic:

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            Color gameColor = GameConstants.PaidVersion ? Color.Blue : Color.Red;
            GraphicsDevice.Clear(gameColor);

            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();
            spriteBatch.DrawString(
                this.font,
                "Game Version: " + (GameConstants.PaidVersion ? "Pro" : "Lite"),
                new Vector2(10,10),
                Color.Black);

            spriteBatch.DrawString(
                this.font,
                "Is Trial: " + (GameConstants.IsTrial ? "Yes" : "No"),
                new Vector2(10, 30),
                Color.Black);

            spriteBatch.DrawString(
                this.font,
                "Show Ads: " + (GameConstants.ShowAds ? "Yes" : "No"),
                new Vector2(10, 50),
                Color.Black);

            spriteBatch.End();
            base.Draw(gameTime);
        }

Now, if we set our solution configuration to “Lite”:

And run the app, we see the following:

The app title appears as follows:

And the tile shows up as:

Simply switch to solution configuration of “Pro” in Visual Studio from the configuration drop-down:

Now the app runs as:

With a title that shows up as:

And a tile that looks like:

All that with just the push of a single button! When it comes time to ship, simply build your solution under both configurations and you will have two XAPs, your Pro and Lite version, for submission.

(Note: to test the Trial version, in the GameConstants class you can set Guide.SimulateTrialMode to true and then IsTrial should start returning True.)

Taking the time to set this up for your game project files can be a huge savings managing different versions. We found it tremendously helpful in testing and shipping paid and free versions and making sure we got each right.

You can download the complete sample code for this tutorial with all of the above config and settings in place here: VersionGame Sample.

3 Comments on “Tutorial – Using Visual Studio Solution Configuration to Manage Free and Paid Game Versions”

  1. #1 Joyelle
    on Nov 20th, 2011 at 1:38 am

    Please keep thrnoiwg these posts up they help tons.

  2. #2 BlackLight
    on Jan 4th, 2012 at 9:40 am

    Hi,

    Great solution to the problem. One question though. What happens with the application Guid. The Guid is used to refer to your app in the market place. This needs to be switched too.

  3. #3 Joel
    on Jan 4th, 2012 at 3:12 pm

    The app guid should actually get updated in-place when you submit your app for approval, so in most cases you shouldn’t need to manage the app guid yourself.

Leave a Comment