I'm trying to follow a course to create apps using C#, unfortunately I'm using a Mac so I can't follow all the step as the y do it on the videos. I.E. the method to create an empty class is different, Had to manually include the Entity Framework Dependency and create the Models folder.... but now I'm trying to create a Controller by scaffolding it but I can't see how to do it. I don't know if there's a better option than using VS or if I need to install some basic plugins or packages to make it a 'windows-esque' experience.
P.S.: I'm a total noob regarding C#, this is the first time I work on it so it's not as easy as saying "well, you can manually create your controller and the datacontext file" 'cause I'm not really familiar with which files I need to make the project running, that's the reason to stick with VS, since it seems to help you during all the develop process [or at least in Windows].
I ran into the same issue going through an older Microsoft tutorial (https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro?view=aspnetcore-2.2).
Answer: the scaffolding needs to be done from the command line using dotnet aspnet-codegenerator. The documentation (including the options for scaffolding controllers) can be found here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/tools/dotnet-aspnet-codegenerator?view=aspnetcore-2.2
For the tutorial I linked above the controller scaffolding was done with the following command:
dotnet aspnet-codegenerator controller -name StudentsController -m Student -dc SchoolContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries --useAsyncActions
-m is the name of the model. -dc is the database context.
The aspnet-codegenerator tool has to be installed using the following command:
dotnet tool install -g dotnet-aspnet-codegenerator
I also had to add the Microsoft.VisualStudio.Web.CodeGeneration.Design NuGet package as a project dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With