I have a C# .Net 4 class library that I think I have set up to be an Azure Worker Role, i.e. the class implements Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint and has a Run() and an OnStart() method. However when I right-click on the Roles folder in my empty Windows Azure project and click Add the option to add a "Worker role project in solution …" is greyed out. What do I need to do for VS2010 to realise there's a potential worker role project in the solution?
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
© 2022 - 2024 — McMap. All rights reserved.