我有一个控制台应用程序,正在部署到Azure应用程序服务。该应用程序在本地计算机上运行时运行良好,但当我将其发布到Azure时,我会收到以下错误:
Application: w3wp.exe
CoreCLR Version: 6.0.922.41905
.NET Version: 6.0.9
Description: The process was terminated due to an unhandled exception.
Exception Info: Azure.Identity.CredentialUnavailableException: Azure CLI not installed
at Azure.Identity.AzureCliCredential.RequestCliAccessTokenAsync(Boolean async, TokenRequestContext context, CancellationToken cancellationToken)
at Azure.Identity.AzureCliCredential.GetTokenImplAsync(Boolean async, TokenRequestContext requestContext, CancellationToken cancellationToken)
at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage)
at Azure.Identity.AzureCliCredential.GetTokenImplAsync(Boolean async, TokenRequestContext requestContext, CancellationToken cancellationToken)
at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](ValueTask`1 task)
at Azure.Identity.AzureCliCredential.GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken)
...
访问密钥库的代码如下所示:
AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
_configuration.Bind("Authentication", authenticationConfiguration);
SecretClient keyVaultClient = new SecretClient(
new Uri(_configuration.GetValue<string>("KeyVaultUri")),
new DefaultAzureCredential());
authenticationConfiguration.AccessTokenSecret = keyVaultClient.GetSecret("access-token-secret").Value.Value;
services.AddSingleton(authenticationConfiguration);
如何在Azure Web Service中安装Azure CLI(或如何正确访问控制台应用程序中的密钥保管库(?
将应用程序发布为"自包含"解决了问题。