With visual studio 2017, when I try to set a user secret I get the following error:
> dotnet user-secrets set Authentication:Google:ClientId mysecretclientid
> Could not find the global property 'UserSecretsId' in MSBuild project 'c:\test\myproj.csproj'. Ensure this property is set in the project or use the '--id' command line option.
I have this in my Startup.cs:
[assembly: UserSecretsId("project-8084c8e7-0000-0000-b266-b33f42dd88c0")]
...
builder.AddUserSecrets<Startup>();
If I add this to my csproj:
<PropertyGroup>
<UserSecretsId>project-8084c8e7-0000-0000-b266-b33f42dd88c0</UserSecretsId>
</PropertyGroup>
I get an error saying
Duplicate 'Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute'
What am I doing wrong?
The inner text is arbitrary, but is unique to the project. In Visual Studio, right-click the project in Solution Explorer, and select Manage User Secrets from the context menu.
All you need to do is select the project in the Solution Explorer window, right-click on the project, and then select Manage User Secrets as shown in Figure 1 below. This will open the secrets. json file in your Visual Studio IDE.
Your secrets are stored in a JSON file under your user profile. In a Windows machine, they are stored in the %APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets. json file.
In VS Code 2019, you can use the command below to generate the UserSecret section within your csproj file. Please make sure you are within the directory containing the desired csproj file when running the command.
dotnet user-secrets init
I got the same error and I fixed it by generating a new UserSecretsId.
The UserSecretsId will be generated automatically if you right click on the Project in the Solution Explorer and press Manage User Secrets
.
Ok, so I got it working, looks like in VS 2017 you should remove the "[assembly: UserSecretsId("project-8084c8e7-0000-0000-b266-b33f42dd88c0")]
" attribute and have the following in the csproj file:
<PropertyGroup>
<UserSecretsId>project-8084c8e7-0000-0000-b266-b33f42dd88c0</UserSecretsId>
</PropertyGroup>
If you are using external caching provider such as redis put this in your .csproj file
<PropertyGroup><UserSecretsId>Redistest</UserSecretsId></PropertyGroup>
Redistest is secret name. It could be anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With