Running dotnet ef dbcontext scaffold name=con Microsoft.EntityFrameworkCore.SqlServer fails with ...the name 'con' was not found in the application's configuration. .... What is missing from the following sequence of steps?
Not a duplication!
- .NET 6: how to get user-secrets working in a class library? is dealing with copying the
<UserSecretsId>tag from one project to another, and moving from/to solution root dir. This question is much simpler:
Steps:
In an empty folder c:\my\temp\proj I ran the following commands:
dotnet new classlib -f net6.0
dotnet user-secrets init
dotnet user-secrets set con "my connection string"
Then examined proj.csproj and noticed that this entry was added:
<UserSecretsId>bce3b7d0-c6f7-4bd0-b808-841dbfd10bea</UserSecretsId>
And the new secrets.json which was created under:
%APPDATA%\Microsoft\UserSecrets\bce3b7d0-c6f7-4bd0-b808-841dbfd10bea\
Containing:
{
"con": "my connection string"
}
And then ran:
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet ef dbcontext scaffold name=con Microsoft.EntityFrameworkCore.SqlServer
Which eventually gave this error: A named connection string was used, but the name 'con' was not found in the application's configuration. Note that named connection strings are only supported when using 'IConfiguration' and a service provider, such as in a typical ASP.NET Core application. See https://go.microsoft.com/fwlink/?linkid=850912 for more information.
Even if I create an appsettings.json file containing e.g. { "con": "N/A" } I'm getting the same result.