Reputation: 6515
I have an existing .Net 5 Blazor Server application. No authentication or authorization at this point. I am attempting to add Microsoft Identity via scaffolding but continue to get the the following error when I attempt to scaffold Identity into the project which I can not resolve "There was an error in the selected code generator 'Package restore failed. Rolling back package changes [MySolujtionName] Server."
Thing's I have tried:
So far no luck and I continue to get the same error.
Upvotes: 1
Views: 1796
Reputation: 31
I'm working with Blazor Server. I started my project with Identity templated and I'm getting errors when I try the command line solution above.
The errors I got after trying to scaffold pages are ones that make me think the scaffolder doesn't really understand the conventions around Blazor. The scaffolder fails to build (even though a normal build completes) because of things like Component Lifecycle methods, Singleton references in _ViewImports.cshtml, and references to the components themselves... Screengrab 1 Screengrab 2
I'm using Net 5.0, I'm not sure if this is already solved in Net 6.0.
I ended up deleting my Components folder and all references to them. Scaffolded all the pages (so I don't have to do this again), then restored the folder using version control.
Upvotes: 0
Reputation: 6515
I copied and pasted this from Nicolas Biada above to point out that this was the part that was the actual resolution.
UPDATE
I've found a bug in the Visual Studio Generator. The only possibility to scaffold the Identity pages from an existing project is to execute the scaffolding process via command line.
Here is an example of the command line:
dotnet aspnet-codegenerator identity -dc TestWasmAuthIndividual.Server.Data.ApplicationDbContext --files "Account.Register;Account.Login;Account.Logout;Account.Manage.PersonalData" --force
you need to execute this command line from the Server project.
Upvotes: 3
Reputation: 2800
I've tried with a new Blazor Server project and it works with:
then the scaffolding works as expected.
I obtain the following structure:
The User model class generated by the scaffolder will be:
namespace Test2.Areas.Identity.Data
{
// Add profile data for application users by adding properties to the Test2User class
public class Test2User : IdentityUser
{
}
}
I've found a bug in the Visual Studio Generator.
The only possibility to scaffold the Identity pages from an existing project is to execute the scaffolding process via command line.
Here is an example of the command line:
dotnet aspnet-codegenerator identity -dc TestWasmAuthIndividual.Server.Data.ApplicationDbContext --files "Account.Register;Account.Login;Account.Logout;Account.Manage.PersonalData" --force
you need to execute this command line from the Server project.
Upvotes: 5