{"id":3727,"date":"2024-01-20T07:00:43","date_gmt":"2024-01-20T07:00:43","guid":{"rendered":"https:\/\/jamiemaguire.net\/?p=3727"},"modified":"2024-01-16T08:17:07","modified_gmt":"2024-01-16T08:17:07","slug":"using-aspnet-codegenerator-to-run-identity-code-generation","status":"publish","type":"post","link":"https:\/\/jamiemaguire.net\/index.php\/2024\/01\/20\/using-aspnet-codegenerator-to-run-identity-code-generation\/","title":{"rendered":"Using aspnet-codegenerator to Run Identity Code Generation"},"content":{"rendered":"<p class=\"p1\">I recently experienced issues using the scaffolding feature in Visual Studio 2022 when building my next SaaS MVP <a href=\"https:\/\/jamiemaguire.net\/index.php\/2023\/09\/09\/audio-notes-blending-azure-ai-speech-and-azure-language-to-create-a-micro-saas\/\">Audio Notes<\/a>.<\/p>\n<p class=\"p1\">I had used scaffolding before without any issues to auto-generate <a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/security\/authentication\/scaffold-identity?view=aspnetcore-8.0&amp;tabs=visual-studio\">.NET Identity<\/a> views and associated code for a SaaS MVP and was using it again to speed up development.<\/p>\n<p class=\"p1\">Despite being able to initially run the scaffolding tool using the context menu, subsequent attempts failed.<\/p>\n<p class=\"p1\">Different types of error occurred each time.<\/p>\n<p>I had an existing web application using .NET 7.0.<span class=\"apple-converted-space\">\u00a0 <\/span>I mirrored that but it still didn\u2019t work.<\/p>\n<h2 class=\"p1\"><b>Using the Command Prompt<\/b><\/h2>\n<p class=\"p1\">I didn\u2019t 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:<\/p>\n<p class=\"p1\"><code>dotnet aspnet-codegenerator identity -dc AudioNotes.Data.AppDbContext<\/code><\/p>\n<p class=\"p2\">\n<p class=\"p1\">After running the command from the developer prompt I removed the Identity pages and code that were irrelevant, keeping only the ones I required.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1936\" height=\"1056\" class=\"alignnone wp-image-3728 size-full\" src=\"https:\/\/jamiemaguire.net\/wp-content\/uploads\/2024\/01\/Pasted-6.png\" srcset=\"https:\/\/jamiemaguire.net\/wp-content\/uploads\/2024\/01\/Pasted-6.png 1936w, https:\/\/jamiemaguire.net\/wp-content\/uploads\/2024\/01\/Pasted-6-750x409.png 750w, https:\/\/jamiemaguire.net\/wp-content\/uploads\/2024\/01\/Pasted-6-1400x764.png 1400w, https:\/\/jamiemaguire.net\/wp-content\/uploads\/2024\/01\/Pasted-6-768x419.png 768w, https:\/\/jamiemaguire.net\/wp-content\/uploads\/2024\/01\/Pasted-6-1536x838.png 1536w, https:\/\/jamiemaguire.net\/wp-content\/uploads\/2024\/01\/Pasted-6-816x445.png 816w\" sizes=\"auto, (max-width: 1936px) 100vw, 1936px\" \/><\/p>\n<p class=\"p1\">\n<b>Note<\/b>: this command must be run from the folder that contains your DB Context.<\/p>\n<p>Any generated Entity Framework code can then be applied in the usual manner, e.g.:<\/p>\n<p><code>Add-Migration CreateIdentitySchema<br \/>\nUpdate-Database<\/code><\/p>\n<p class=\"p2\" style=\"text-align: center;\">~<\/p>\n<h2 class=\"p1\"><b>Further Information<\/b><\/h2>\n<p class=\"p1\">You can learn more about the various parameters that <code>aspnet-codegenerator<\/code> can be invoked with by reading the following:<\/p>\n<ul>\n<li><a href=\"https:\/\/learn.microsoft.com\/en-us\/aspnet\/core\/fundamentals\/tools\/dotnet-aspnet-codegenerator?view=aspnetcore-8.0\">dotnet aspnet-codegenerator command | Microsoft Learn<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":3729,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[111,6,115],"tags":[],"class_list":["post-3727","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-audio-notes","category-c","category-visual-studio"],"_links":{"self":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/posts\/3727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/comments?post=3727"}],"version-history":[{"count":0,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/posts\/3727\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/media\/3729"}],"wp:attachment":[{"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/media?parent=3727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/categories?post=3727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jamiemaguire.net\/index.php\/wp-json\/wp\/v2\/tags?post=3727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}