SALES: 1-800-867-1380
Logg på
EN
Dette innholdet er ikke tilgjengelig på ditt språk, men her er den engelske versjonen.
1 av 1 vurderte dette som nyttig - Vurder dette emnet

# How to: Prepare Visual Studio to Use In-Role Cache (Windows Azure Cache)

This topic explains how to prepare a Visual Studio 2012 project to use Windows Azure Cache. This includes the following tasks:

• Verify that the correct version of the .NET Framework is targeted.

• Reference the Cache assemblies.

After these tasks, you can configure your cache client in the dataCacheClient section of the application or web.config files. This enables you to use the Cache methods in the Microsoft.ApplicationServer.Caching namespace.

Warning
You should not install Microsoft AppFabric 1.1 for Windows Server and Windows Azure Cache on the same machine. This includes both the product and the SDK. It is possible to mistakenly reference some of the Microsoft AppFabric 1.1 for Windows Server assemblies in the Global Assembly Cache. This could lead to incorrect or unexpected behavior.

## To target the correct version of the .NET Framework

1. Open your Visual Studio 2012 project.

2. In Solution Explorer, right-click the project name and then select Properties.

3. For a Visual C# project, use the following steps:

1. Select the Application tab of the Project Properties dialog.

2. Verify that the target framework version is .NET Framework 2.0 or higher (non-client profile).

4. For a Visual Basic project, use the following steps:

1. Select the Compile section of the Project Properties page.

2. At the bottom of the Compile page, click the Advanced Compile Options button.

3. Verify that the target framework version is .NET Framework 2.0 or higher (non-client profile).

Important
Do not use the client profile for the target framework version. In Visual Studio, select .NET Framework versions that do not specify "Client Profile".

## Configure a Project for Caching on Roles

To add the assembly references, you must have the Windows Azure SDK installed on your machine. For instructions, see Windows Azure SDK Download.

The following steps use a NuGet package to add the necessary assembly references and configuration changes. These steps are specific to using In-Role Cache that is hosted on a Windows Azure role in the same deployment.

1. In Solution Explorer, right-click on the project name, and then select Add Library Package Reference (NuGet 1.2) or Manage NuGet Packages (NuGet 2.0).

2. In the left pane, select the Online category.

3. Search for WindowsAzure.Caching.

4. Install the In-Role Cache package named Microsoft.WindowsAzure.Caching (NuGet 1.2) or Windows Azure Caching (NuGet 2.0).

In addition to adding the appropriate assembly references, this package also modifies the configuration file (app.config or web.config) for the targeted project. It adds a boilerplate dataCacheClient section similar to the following.

<dataCacheClients>
<dataCacheClient name="default">
<autoDiscover isEnabled="true" identifier="[cache cluster role name]" />
<!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
</dataCacheClient>
</dataCacheClients>


The final step is to change the identifier attribute from "[cache cluster role name]" to the actual name of the role that has In-Role Cache enabled. In a co-located topology, this could be the same role, such as "WebRole1". In a dedicated topology, this could be a different role, such as "CacheWorkerRole1". For samples of both topologies, see In-Role Cache Samples (Windows Azure Cache).

Note
Uninstalling the NuGet package does not remove the dataCacheClients section if that section has been customized. It must be removed manually.

The NuGet package adds references to the following assemblies:

• Microsoft.ApplicationServer.Caching.AzureClientHelper

• Microsoft.ApplicationServer.Caching.AzureCommon

• Microsoft.ApplicationServer.Caching.Client

• Microsoft.ApplicationServer.Caching.Core

• Microsoft.Web.DistributedCache

• Microsoft.WindowsFabric.Common

• Microsoft.WindowsFabric.Data.Common

Note
It is possible to manually reference these assemblies without the NuGet package. By default, they are installed to C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-10\ref\Caching.