I have some shared assemblies/projects that are used within Winforms apps, windows services and now Azure worker roles.
Is there any way that I can detect at runtime
We set an environment variable (in this example INAZURE) as a startup task via a batch file.
Contents of SetEnvVar.cmd batch file:
setx INAZURE True /M
Configure the batch file to start via your cscfg file:
Then write something to read this environment variable. There is a static RoleEnvironment class in the Azure SDK you can use, but this references nasty unmanged assemblies that make build server configuration a PITA. Things may have gotten better in more recent releases of the Azure SDK.
I have a closely related blog article at: http://adrianwithy.com/2012/02/06/remove-msshrtmi-dll-as-a-dependency-in-your-azure-project/