Can I detect if my code is executing in an Azure worker role?

前端 未结 5 1920
情深已故
情深已故 2021-01-18 13:24

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

5条回答
  •  渐次进展
    2021-01-18 13:58

    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/

提交回复
热议问题