Why is Azure Add > Worker role project in solution … greyed out in VS2010?
The "Add > Worker Role Project in solution..." only displays worker role projects not class libraries. Even though they look the same, they aren't.
You can create a worker role project by using the following:
- When creating a new cloud project
- By right clicking a cloud project
Then you'll be able to add that worker role project in an other cloud project if you like. In that case the "Add > Worker Role Project in solution..." menu option will be enabled.
Now, you can also 'convert' a class library to a worker role project. Right click the class library and choose Unload Project .. then (once that's unloaded), Edit Project File and add the RoleType element in the first property group:
<PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>8.0.30703</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{7E9F972F-BE92-4CF7-998D-E76B61B21C37}</ProjectGuid> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>ClassLibrary1</RootNamespace> <AssemblyName>ClassLibrary1</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <RoleType>Worker</RoleType> <-------------------- HERE </PropertyGroup>
Finally - reload the project back into the solution -> Right-Click Reload Project. (NOTE: if the Xml file is still open, you'll get asked to close it.. which is perfect. Say yes and close it). .. Now your class library has been re-added back but it's a Worker Role Class Library.
If you do this, Visual Studio will recognize the project as being a worker role and you'll be able to add it to the cloud project:
Note: Your class library will need a class deriving from RoleEntryPoint. More information: http://blogs.msdn.com/b/jnak/archive/2010/02/11/windows-azure-roleentrypoint-method-call-order.aspx