In my automated NAnt build we have a step that generates a lot of code off of the database (using SubSonic) and the code is separated into folders that match the schema name in the database. For example:
在我的自动NAnt构建中,我们有一个步骤可以从数据库中生成大量代码(使用SubSonic),代码被分成与数据库中的模式名称匹配的文件夹。例如:
- /generated-code
- /dbo
- SomeTable.cs
- OtherTable.cs
- /abc
- Customer.cs
- Order.cs
/ dbo SomeTable.cs OtherTable.cs
/ abc Customer.cs Order.cs
- /dbo
/ generated-code / dbo SomeTable.cs OtherTable.cs / abc Customer.cs Order.cs
The schema names are there to isolate the generated classes that an app will need. For example, there is an ABC app, that will pull in the generated code from this central folder. I'm doing that on a pre-build event, like this:
模式名称用于隔离应用程序所需的生成类。例如,有一个ABC应用程序,它将从此*文件夹中提取生成的代码。我在预构建事件中这样做,如下所示:
del /F /Q $(ProjectDir)Entities\generated*.cs
del / F / Q $(ProjectDir)实体\生成* .cs
copy $(ProjectDir)....\generated-code\abc*.cs $(ProjectDir)Entities\generated*.cs
copy $(ProjectDir).... \ generated-code \ abc * .cs $(ProjectDir)Entities \ generated * .cs
So on every build, the Nant script runs the generator which puts all the code into a central holding place, then it kicks off the solution build... which includes pre-build events for each of the projects that need their generated classes.
因此,在每个构建中,Nant脚本运行生成器,将所有代码放入*控制位置,然后启动解决方案构建...其中包括需要生成的类的每个项目的预构建事件。
So here's the friction I'm seeing:
所以这就是我所看到的摩擦:
1) Each new app needs to setup this pre-build event. It kind of sucks to have to do this.
1)每个新应用程序都需要设置此预构建事件。不得不这样做很糟糕。
2) In our build server we don't generate code, so I actually have an IF $(ConfigurationName) == "Debug" before each of those commands, so it doens't happen for release builds
2)在我们的构建服务器中,我们不生成代码,所以我实际上在每个命令之前都有一个IF $(ConfigurationName)==“Debug”,因此对于发布版本不会发生
3) Sometimes the commands fail, which fails our local build. It will fail if: - there is no generated code yet (just setting up a new project, no database yet) - there is no existing code in the directory (first build)
3)有时命令失败,这使我们的本地构建失败。如果出现以下情况,它将失败: - 还没有生成代码(只是设置一个新项目,还没有数据库) - 目录中没有现有代码(第一次构建)
usually these are minor fixes and we've just hacked our way to getting a new project or a new machine up and running with the build, but it's preventing me from my 1-click-build Nirvana.
通常这些是小修复,我们只是破解了我们的方式来获得一个新的项目或新的机器运行与构建,但它阻止我从我的单击构建Nirvana。
So I'd like to hear suggestions on how to improve this where it's a bit more durable. Maybe move the copying of the code into the application folders into the NAnt script? This seems kind of backwards to me, but I'm willing to listen to arguments for it.
因此,我想听听有关如何改善这一点的建议。也许将代码复制到应用程序文件夹中转移到NAnt脚本中?这似乎对我不利,但我愿意听取它的论据。
OK, fire away :)
好吧,开火:)
3 个解决方案
#1
1
How often does your DB schema change? Wouldn't it be possible to generate the database-related files on demand (e.g. when the schema changes) and then check them into your code repository?
您的数据库架构多久更改一次?是否有可能按需生成与数据库相关的文件(例如,当架构更改时),然后将它们检入您的代码库?
If your database schema doesn't change, you can also package the compiled *.cs classes and distribute the archive to other projects.
如果数据库模式未更改,则还可以打包已编译的* .cs类并将存档分发到其他项目。
#2
0
We have two projects in our solution that are built completely out of generated code. Basically, we run the code generator .exe as a post-build step for another project and along with generating the code, it automates the active instance of visual studio to make sure that the generated project is in the solution, that it has all of the generated code files, and that they are checked out/added to TFS as necessary.
我们的解决方案中有两个项目完全由生成的代码构建。基本上,我们运行代码生成器.exe作为另一个项目的构建后步骤,并生成代码,它自动化visual studio的活动实例,以确保生成的项目在解决方案中,它具有全部生成的代码文件,并根据需要将它们签出/添加到TFS。
It very rarely flakes out during the VS automation stage, and we have to run it "by hand" but that's usually only if you have several instances of VS open with >1 instance of the solution open and it can't figure out which one it's supposed to automate.
它很少在VS自动化阶段剥落,我们必须“手动”运行它,但这通常只有当你打开几个VS的实例并打开一个解决方案的实例时,它才能找出哪一个它应该是自动化的。
Our solution and process are such that the generation should always be done and correct before our auto-build gets to it, so this approach might not work for you.
我们的解决方案和流程是这样的,在我们的自动构建之前,应该始终完成生成和更正,因此这种方法可能对您不起作用。
#3
0
Yeah I'd like to take VS out of the equation so that a build from VS is just simply compiling the code and references.
是的,我想把VS从等式中取出,这样VS的构建只是简单地编译代码和引用。
I can manage the NAnt script... I'm just wondering if people have advice around having 1 NAnt script, or possibly one for each project which can push the code into the projects rather than being pulled.
我可以管理NAnt脚本...我只是想知道人们是否有关于拥有1个NAnt脚本的建议,或者每个项目可能有一个可以将代码推送到项目而不是被拉动的项目。
This does mean that you have to opt-in to generate code.
这意味着您必须选择生成代码。
#1
1
How often does your DB schema change? Wouldn't it be possible to generate the database-related files on demand (e.g. when the schema changes) and then check them into your code repository?
您的数据库架构多久更改一次?是否有可能按需生成与数据库相关的文件(例如,当架构更改时),然后将它们检入您的代码库?
If your database schema doesn't change, you can also package the compiled *.cs classes and distribute the archive to other projects.
如果数据库模式未更改,则还可以打包已编译的* .cs类并将存档分发到其他项目。
#2
0
We have two projects in our solution that are built completely out of generated code. Basically, we run the code generator .exe as a post-build step for another project and along with generating the code, it automates the active instance of visual studio to make sure that the generated project is in the solution, that it has all of the generated code files, and that they are checked out/added to TFS as necessary.
我们的解决方案中有两个项目完全由生成的代码构建。基本上,我们运行代码生成器.exe作为另一个项目的构建后步骤,并生成代码,它自动化visual studio的活动实例,以确保生成的项目在解决方案中,它具有全部生成的代码文件,并根据需要将它们签出/添加到TFS。
It very rarely flakes out during the VS automation stage, and we have to run it "by hand" but that's usually only if you have several instances of VS open with >1 instance of the solution open and it can't figure out which one it's supposed to automate.
它很少在VS自动化阶段剥落,我们必须“手动”运行它,但这通常只有当你打开几个VS的实例并打开一个解决方案的实例时,它才能找出哪一个它应该是自动化的。
Our solution and process are such that the generation should always be done and correct before our auto-build gets to it, so this approach might not work for you.
我们的解决方案和流程是这样的,在我们的自动构建之前,应该始终完成生成和更正,因此这种方法可能对您不起作用。
#3
0
Yeah I'd like to take VS out of the equation so that a build from VS is just simply compiling the code and references.
是的,我想把VS从等式中取出,这样VS的构建只是简单地编译代码和引用。
I can manage the NAnt script... I'm just wondering if people have advice around having 1 NAnt script, or possibly one for each project which can push the code into the projects rather than being pulled.
我可以管理NAnt脚本...我只是想知道人们是否有关于拥有1个NAnt脚本的建议,或者每个项目可能有一个可以将代码推送到项目而不是被拉动的项目。
This does mean that you have to opt-in to generate code.
这意味着您必须选择生成代码。