-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Visual Studio Version
16.11.5
.NET Framework 5 (SDK 5.0.402)
Summary
Setting the GenerateAssemblyInfo property to false in an ASP.NET Core .csproj file prevents user secrets from being loaded. Instead of the value stored in secrets.json null is returned.
Steps to Reproduce
- Create a new "ASP.NET Core Web API" project.
- In the newly created project directory execute the command
dotnet user-secrets init. - Add a new user secret by executing the command
dotnet user-secrets set "Key" "12345". - In the
ConfigureServicesmethod of theStartup.csfile addstring key = Configuration["Key"];as the first line of the method. - Set a break point to the second line of the above mentioned method and build and start the program with the attached debugger. The
keyvariable contains the value 12345. - Edit the .csproj file of the project and add the MSBuild property
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>to the existingProjectGroup. - Compile and start the program again. The
keyvariable will now containnullinstead of 12345.
Workaround
Add an AssemblyInfo.cs file to the project and add [assembly: UserSecretsId("GUID")] where GUID is the same GUID that is stored in the UserSecretsId property of the .csproj file.
Expected Behavior
The key variable should still contain 12345, not null without being forced to add the UserSecretsId to the AssemblyInfo.cs file.
User Impact
I've wasted several hours to figure out how to make user secrets work. There is no obvious connection between setting GenerateAssemblyInfo to false and not being able to read user secrets anymore which means that users will not figure out easily what the problem is even when doing online searches.
There is little justification for being forced to add the UserSecretsId attribute to the AssemblyInfo.cs file if it is already present in the .csproj file.