For code that should be agnostic for the cloud, it might be a good idea to use an environment variable. For services running on Windows Azure, you should add something like:
<Runtime> <Environment> <Variable name="INCLOUD" value="true" /> </Environment> ...
This env variable will now only display in Windows Azure (unless you install it locally, if not in the cloud, of course). Your code should not "know" anything about RoleEnvironment or the ServiceHosting.dll link.
If you need to determine if you are working in emulation or using any RoleEnvironment parameters, you can also use new variables based on the Xpath variable. For more information about it http://msdn.microsoft.com/en-us/library/windowsazure/hh404006.aspx .
source share