Is there any possibilities to change default projects and folders where MvcScaffolding generates repositories, views and controllers?
Asked
Active
Viewed 1,200 times
3 Answers
1
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/

Paweł Staniec
- 3,151
- 3
- 29
- 41
-
It's good solution but is there way to set paths for permanently? – user1243077 Jan 14 '13 at 14:43
-
not sure about permanently but you can try ' set scaffolder "/My/Folder" ' and then just use $scaffolder – Paweł Staniec Jan 14 '13 at 15:32
-
1The -Folder option no longer appears to be a part of MvcScaffolding. I can't seem to find the proper way to do this either... – Derek Apr 09 '13 at 14:58
1
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:
- In Package Manager Console:
Scaffold CustomScaffolder MyRepository
- Right-click on the solution and "Open folder in Windows Explorer"
- Navigate to "packages\T4Scaffolding.1.0.8\tools\EFRepository"
- 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).
- Change the output path specified in the ps1 file e.g.
$outputPath = Join-Path Repositories ($foundModelType.Name + "Repository")
- Change the template file specified in the new ps1 file to the new template file name e.g.
Add-ProjectItemViaTemplate $outputPath -Template MyRepository
- 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"

Colin
- 22,328
- 17
- 103
- 197
0
Regarding the repository scaffolder:
- Go to packages\T4Scaffolding.1.0.8\tools\EFRepository inside your solution folder.
- Right click on T4Scaffolding.EFRepository script and select Edit
- Find the line $outputPath = Join-Path Models ($foundModelType.Name + "Repository") and replace the word "Models" with your desired folder name/path
- Close and save the script
Regarding the other scaffolders (Action, View, etc..)
- Just the same above steps except that the scripts are located in the packages\MvcScaffolding.1.0.9\tools folder

Mohamed Emad
- 1,113
- 1
- 9
- 16