How to change project and folder where MvcScaffolding generates controllers, views and repositories

StackOverflow https://stackoverflow.com/questions/14318159

Question

Is there any possibilities to change default projects and folders where MvcScaffolding generates repositories, views and controllers?

Was it helpful?

Solution

You can if you're triggering scaffolding from Command Window

For example:

> Scaffold DbContext <modelType> <dbContextName> -Folder /Models/Entities

More info http://blog.stevensanderson.com/2011/01/13/mvcscaffolding-standard-usage/

OTHER TIPS

The output folder is specified in the powershell script that runs the template. You need to generate custom scaffolders, and set them as the default scaffolders. Here's how I did it for a repository:

  1. In Package Manager Console: Scaffold CustomScaffolder MyRepository
  2. Right-click on the solution and "Open folder in Windows Explorer"
  3. Navigate to "packages\T4Scaffolding.1.0.8\tools\EFRepository"
  4. Copy the contents of the ps1 powershell script and the t4 template file into the ps1 and t4 files created in step 1 (overwriting the scaffolded text).
  5. Change the output path specified in the ps1 file e.g. $outputPath = Join-Path Repositories ($foundModelType.Name + "Repository")
  6. Change the template file specified in the new ps1 file to the new template file name e.g. Add-ProjectItemViaTemplate $outputPath -Template MyRepository
  7. Change the default template for repositories to the new template: Set-DefaultScaffolder Repository MyRepository

The views and controllers should be a similar process, except the original ps1 and t4 files are in "packages\MvcScaffolding.1.0.9\tools"

Regarding the repository scaffolder:

  1. Go to packages\T4Scaffolding.1.0.8\tools\EFRepository inside your solution folder.
  2. Right click on T4Scaffolding.EFRepository script and select Edit
  3. Find the line $outputPath = Join-Path Models ($foundModelType.Name + "Repository") and replace the word "Models" with your desired folder name/path
  4. Close and save the script

Regarding the other scaffolders (Action, View, etc..)

  1. Just the same above steps except that the scripts are located in the packages\MvcScaffolding.1.0.9\tools folder
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top