Software Architect / Microsoft MVP (AI) and Technical Author

Audio Notes, C#, Visual Studio

Using aspnet-codegenerator to Run Identity Code Generation

I recently experienced issues using the scaffolding feature in Visual Studio 2022 when building my next SaaS MVP Audio Notes.

I had used scaffolding before without any issues to auto-generate .NET Identity views and associated code for a SaaS MVP and was using it again to speed up development.

Despite being able to initially run the scaffolding tool using the context menu, subsequent attempts failed.

Different types of error occurred each time.

I had an existing web application using .NET 7.0.  I mirrored that but it still didn’t work.

Using the Command Prompt

I didn’t have time to burn and found that bypassing the GUI and running the following command from the command prompt created the code and pages that I needed:

dotnet aspnet-codegenerator identity -dc AudioNotes.Data.AppDbContext

After running the command from the developer prompt I removed the Identity pages and code that were irrelevant, keeping only the ones I required.

Note: this command must be run from the folder that contains your DB Context.

Any generated Entity Framework code can then be applied in the usual manner, e.g.:

Add-Migration CreateIdentitySchema
Update-Database

~

Further Information

You can learn more about the various parameters that aspnet-codegenerator can be invoked with by reading the following:

 

JOIN MY EXCLUSIVE EMAIL LIST
Get the latest content and code from the blog posts!
I respect your privacy. No spam. Ever.

Leave a Reply