ASP Core Cannot Set User Secrets in VS 2017

13,372

Solution 1

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>

Solution 2

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

Solution 3

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.

Share:
13,372
Zeus82
Author by

Zeus82

I work as a C# Developer at a startup.

Updated on June 27, 2022

Comments

  • Zeus82
    Zeus82 almost 2 years

    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?