Last post Aug 16, 2017 06:57 AM by AngelinaJolie
Aug 13, 2017 06:54 AM|fmz|LINK
i want to make this app:
i want to scaffold from model automatically in code when ever user changes the model add a new table or fields my app automatically create controller and view
can you help me how can i generte conyrollers from model i tryed nuget.exe i want to run command line in my code to scaffold from model
i can scaffold with nuget package manager and i can install package with nuget.exe but i can't scaffold with nuget.exe
Aug 14, 2017 06:38 AM|AngelinaJolie|LINK
May i know your real requirement to your project ?
As far as i know we could add ->New Scaffolded Item -> MVC5 Controller With Views,Using Entity Framework and it could create CURD operation and view pages ;
it can't meet your requirement ,right?
Aug 14, 2017 04:20 PM|fmz|LINK
thank you for your attention to my question
in that way which you explain programmer can scaffold in visual studio but i want to scaffold in run time via code base on changed model.
my web site's user should can change model classes or add class to model in site in run time (not in visual studio that programmer can do) then my app should generate scaffolding controller and view via code based on changed model
Aug 15, 2017 01:26 PM|fmz|LINK
I have a crm web service that have database. my app connects to this crm and have create update and delete views and users can create update and delete crm's datas. users also can create tables in crm, create fields or change field's type and feild's
name or change table's name. and my app should automatically create forms and views for that new or changed tables and my app should have the possibility to create and update and delete with that new or changed crm's database
Aug 16, 2017 06:57 AM|AngelinaJolie|LINK
I am not very sure ,but as far as i know ,only in .net core (MVC 6) ,there are PowerShell Command:
Scaffold-DbContext (Get-Help Scaffold-DbContext) and
CLI Command: dotnet aspnet-codegenerator --help could generate CURD VIews and controller based on model and DBcontext;
1 CLI Command:
dotnet aspnet-codegenerator --project "E:\Documents\Article\ScaffoldingCoreMVC\CoreMVCScaffolding\src\CoreMVCScaffolding"
controller --force --controllerName ContactsController
--model CoreMVCScaffolding.Models.Contacts --dataContext CoreMVCScaffolding.Models.PhoneBookContext --relativeFolderPath
Controllers --controllerNamespace CoreMVCScaffolding.Controllers –useDefaultLayout
From my another thread : https://forums.asp.net/t/2112624.aspx?yeoman+aspnet+mvccontroller+generator+with+scaffolding
2 Power Shell Command:
Scaffold-DbContext [-Connection] <String> [-Provider] <String> [-OutputDir <String>] [-Context <String>] [-Schemas <String>] [-Tables <String>] [-DataAnnotations] [-Force] [-Project <String>] [-StartupProject
From .net core https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#usage
1 ,to know how to call CLI commands in C#:
/// <span class="code-SummaryComment"><returns>string, as output of the command.</returns></span>
public void ExecuteCommandSync(object command)
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
catch (Exception objException)
// Log the exception
2 or how to call powershell in C#:
private string RunScript(string scriptText)
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
// add an extra command to transform the script
// output objects into nicely formatted strings
// remove this line to get the actual objects
// that the script returns. For example, the script
// "Get-Process" returns a collection
// of System.Diagnostics.Process instances.
// execute the script
Collection<psobject /> results = pipeline.Invoke();
// close the runspace
// convert the script result into a single string
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
Maybe you could try a create .net core application for it ;
(official article about .net core )https://docs.microsoft.com/en-us/dotnet/core/tutorials/