1

I have an ASP.NET Core 2.0 app and I can use user secrets just fine. However, I have not been able to get it to work in an Azure WebJobs app or a basic windows console app (both of which are .NET 4.6.1). I have added the nuget for Microsoft.Extensions.Configuration.AddSecrets and the method AddUserSecrets is being compiled fine inside the code.

However, I can't add the user secret to the project. There is no Manage User Secrets option on the right click context menu on the project as there is on the ASP.Net Core 2.0 app. So I try to use dotnet user-secrets from the command line (which I have used successfully in ASP.NET Core 2.0 apps). It doesn't work though as I get this error.

No executable found matching command "dotnet-user-secrets"

From reading other posts it looks like I need to have Microsoft.Extensions.SecretManager.Tools. I can't add this via nuget because I get this error:

so I have added: Severity Code Description Project File Line Suppression State Error Package 'Microsoft.Extensions.SecretManager.Tools 2.0.0' has a package type 'DotnetCliTool' that is not supported by project 'xxx'. 0

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
  </ItemGroup>

to the csproj and attempted to restore the packages. At which point I get another error:

C:\Program Files\dotnet\sdk\2.0.0\NuGet.targets(102,5): error : Value cannot be null.\r [C:\...\xxx.csproj]
C:\Program Files\dotnet\sdk\2.0.0\NuGet.targets(102,5): error : Parameter name: key [C:\...\xxx]

So now I am wondering if user secrets is even support in .NET 4.6.1 projects. If it is, what am I missing?

EDIT: I tracked down the secrets.json from the ASP.NET Core 2.0 app and copied it to a newly created folder suitable for this console app and the user secret is picked up properly. So it appears it works correctly from a usage point of view. The problem I have is actually setting the secret in a convenient way.

1 Answers1

0

According to the Microsoft.Extensions.SecretManager.Tools dependencies, you could find the tool now only support the net core, not support the .net 4.6.

enter image description here

Besides, according to this article, you could find this tool is only used in the development environment.

The most important point is you should never store passwords or other sensitive data in source code, and you shouldn't use production secrets in development and test mode.

If you want to use it in azure webjobs, I suggest you could consider using Azure Key Vault.

The Secret Manager tool is used only in development. You can safeguard Azure test and production secrets with the Microsoft Azure Key Vault configuration provider. See Azure Key Vault configuration provider for more information.

Besides, if you still want to use Microsoft.Extensions.SecretManager, we could use .net core to create azure webjobs. About how to create it, you could refer to this answer.

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65