本文介绍了自动检测所有型号脚手架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多模型一个ASP.NET MVC 4项目,在一个自定义的方式来脚手架。我已经定制了模板来创建控制器和视图我多么希望他们。这一切工作正常。现在,我已经写了一个PowerShell脚本生成控制器和一次一对夫妇的意见为需要被脚手架每个模型。这也能正常工作。

I have an ASP.NET MVC 4 project with a lot of models to be scaffolded in a custom way. I have customized the templates to create the controllers and views how I want them to be. This all works fine. Now I've written a PowerShell script to generate the controller and a couple of views at one time for each model that needs to be scaffolded. This also works fine.

然后我去寻找一个PowerShell脚本脚手架多个模型中的一个命令,因为现在我必须手动运行该脚本,我有每个模型。我发现的第一件事是写一个脚本,每行命令脚手架的模式,这在我看来运行良好,但仍太辛苦了。更深一点的搜索后,我发现,这可能与具有型号列表脚手架和foreach循环迭代列表,然后在该列表中的每个项目执行脚手架命令的脚本来完成。这是好多了!

Then I went looking for a PowerShell script to scaffold multiple models in one command, because now I have to manually run the script for each model that I have. First thing I found was to write a script with on each line the command to scaffold a model, which worked fine but was still too much work in my opinion. After a little deeper searching I found that this could be done with a script that has a list of the models to scaffold and a foreach loop that iterates over the list and then executes the scaffold-command for each item in that list. This was much better!

我问自己,现在的唯一的事情:是否有可能写一些脚本,它会自动检测所有型号的模型文件夹,并将它们在列表中,然后执行循环。之所以我问这是因为我没有只是一对夫妇的车型,但约250。这并不是说我不喜欢人工手动操作,但是如果某些型号的添加,更改或删除什么..

The only thing I'm asking myself now: is it possible to write some script that automatically detects all models in the Model folder, puts them in the list and then performs the loop. Reason why I'm asking this is because I don't have just a couple of models, but about 250. It's not that I don't feel like doing this manually, but what if some models are added, changed or removed...

所以我的问题是:有没有办法为动态获得所有从Model文件夹中的模型,并把它们在将要迭代名单

So my question is: is there a way to 'dynamically' get all the models from the Model folder and put them in the list that will be iterated?

更新:

这是怎么我的脚本ScaffoldAll.ps1现在看起来(不是所有的250款在列表):

This is how my script "ScaffoldAll.ps1" looks now (not all 250 models are in the list):

$models = "Team", "Player"

foreach($model in $models)
{
    Scaffold CustomController $model -Force
}

我要实现什么(!):

$models = //All files in Model folder, like: Get-Files "\Models"

这可能吗?

推荐答案

阿巴斯,

我一直在使用MVCScaffolding模板(使用EF code-第一),而且这个工作原理是,您创建的域模型(S),然后脚手架有一个域模型中的所有对象的方式。此模板实际上将跳过任何pre-现有的控制器/已脚手架意见支架。不过,也有一个覆盖命令(-Force),那么这将覆盖任何/所有pre-已有的脚手架code,如果你愿意的话。

I've been using the MVCScaffolding template (with EF code-first) and the way that this works is that you create your domain model(s) and then scaffold ALL objects that have a domain model. This template will actually skip the scaffold for any pre-existing controllers/views that have been scaffolded. However, there is also an override command (-FORCE) which will then overwrite any/all pre-exisiting scaffolded code if you so wish.

这里的快速链接:

http://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

这篇关于自动检测所有型号脚手架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 19:31