How-To: Show Features Only in Beta Builds

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

By Jared Bienz

I was recently asked how to add a “Submit a Bug” feature to an app but only make it visible for Beta builds.

The code to actually send the bug was quite simple:

EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "My App Feedback";
emailComposeTask.To = "feedback@mydomain.com";
emailComposeTask.Show();

Now the question is where to put it. Obviously this could be triggered from a button click, a menu item, or any other control on the screen. But if we only want the item to show up on beta builds we have some extra work to do.

One of the ways I like to deal with this is by adding a new configuration to the Configuration Manager.

In Visual Studio click the Configuration drop-down and choose “Configuration Manager”.

clip_image001

In Configuration Manager, choose to create a new configuration.

clip_image002

Call the configuration “Beta” and choose to copy settings from Release.

clip_image003

Click OK to close the dialog.

Make sure “Beta” is selected in the configuration drop-down.

Right click on the project and choose “Properties”.

image

Switch to the “Build” tab.

Add a new conditional compile symbol called BETA.

clip_image004

Close the project properties window and make sure you saved your changes.

Now, anywhere in the code you can use BETA as a conditional compile statement.

#if BETA
contactButton.Visibility = Visibility.Visible;
#endif

Now you can easily switch between Debug, Release and Beta builds using the configuration drop-down at the top in Visual Studio!

Reprinted with permission from Microsoft Corporation.

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read