Open
Description
The documentation seems outdated. I pasted the code from the docs, but it doesn't compile for me.
Here is my Program.cs
using Azure.Core;
using Azure.Identity;
using Microsoft.Extensions.Azure;
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.Sources.Clear();
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
config.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
config.AddJsonFile("appsettings.k8s.json", optional: true, reloadOnChange: false);
})
.ConfigureServices((hostContext, services) =>
{
// Registering policy to use in ConfigureDefaults later
services.AddSingleton<DependencyInjectionEnabledPolicy>();
services.AddAzureClients(builder => {
// Register blob service client and initialize it using the KeyVault section of configuration
builder.AddSecretClient(Configuration.GetSection("KeyVault"))
// Set the name for this client registration
.WithName("NamedBlobClient")
// Set the credential for this client registration
.WithCredential(new ClientSecretCredential("<tenant_id>", "<client_id>", "<client_secret>"))
// Configure the client options
.ConfigureOptions(options => options.Retry.MaxRetries = 10);
// Adds a secret client using the provided endpoint and default credential set later
builder.AddSecretClient(new Uri("http://my.keyvault.com"));
// Configures environment credential to be used by default for all clients that require TokenCredential
// and doesn't override it on per registration level
builder.UseCredential(new EnvironmentCredential());
// This would use configuration for auth and client settings
builder.ConfigureDefaults(hostContext.Configuration.GetSection("Default"));
// Configure global retry mode
builder.ConfigureDefaults(options => options.Retry.Mode = RetryMode.Exponential);
// Advanced configure global defaults
builder.ConfigureDefaults((options, provider) => options.AddPolicy(provider.GetService<DependencyInjectionEnabledPolicy>(), HttpPipelinePosition.PerCall));
// Register blob service client and initialize it using the Storage section of configuration
builder.AddBlobServiceClient(Configuration.GetSection("Storage"))
.WithVersion(BlobClientOptions.ServiceVersion.V2019_02_02);
});
})
.Build();
await host.RunAsync();
My csproj file:
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<!-- Code Analysis (https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview) - BEGIN -->
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>Default</AnalysisMode>
<AnalysisLevel>latest</AnalysisLevel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<!-- Code Analysis - END -->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IDisposableAnalyzers" Version="4.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
<Content Update="appsettings.Development.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>
</Project>
Could you please take a look at what might be wrong here?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: fbccd2b0-5ee9-9e5a-55e5-d796bef3bcd3
- Version Independent ID: e8d4c9b1-b45f-6e9e-6d29-8b814221cc35
- Content: Azure client library integration for ASP.NET Core - Azure for .NET Developers
- Content Source: api/overview/azure/latest/microsoft.extensions.azure-readme.md
- Service: extensions
- GitHub Login: @azure-sdk
- Microsoft Alias: azsdkdocs
Metadata
Metadata
Assignees
Labels
This issue points to a problem in the data-plane of the library.ASP.NET Core extensionsThis issue requires a change to an existing behavior in the product in order to be resolved.Issues that are reported by GitHub users external to the Azure organization.Workflow: This issue needs attention from Azure service team or SDK team