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.