Eksportér (0) Udskriv
Udvid alt
Dette indhold er ikke tilgængeligt på dit sprog, men her er den engelske version.

Define Startup Tasks for a Role

Updated: May 9, 2014

You can define a startup task for a role by adding the Startup element to the definition of the role in the service definition file. For more information about these elements, see the Azure Service Definition Schema (.csdef File).

You can edit the ServiceDefinition.csdef file by using your favorite text editor, or you can define the tasks for the role by using Visual Studio.

  1. Open the ServiceDefinition.csdef file for your service in the text editor.

  2. Add the Startup element to the WebRole or WorkerRole; startup tasks are not applicable to the VMRole. The following code example shows how to add a startup task to a web role that runs a command script:

    <ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
       <WebRole name="WebRole1">
             <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
    The commandLine task is relative to the AppRoot\Bin folder for the deployment. Environment variables are not expanded in the commandLine value. If environment expansion is required, you can create a small .cmd script that calls your startup task as cmd.exe, which expands the environment variables.

  3. Set the commandLine value to the name of the program or script file that you want to run.

  4. Set the executionContext to the level of permissions that you want for your startup task.

  5. Set the taskType to simple, foreground, or background depending on how you want the task to run. For more information on taskType, see WorkerRole Schema.

  6. Save the file.

See Also

© 2014 Microsoft