NAnt build file to fix the Project Default Namespace in C#

Hi all,

Following the conversation in http://forums.visual-paradigm.com/posts/list/2592.html, I want to post here the NAnt build file I am already using to help me during the travel from ORM model to Visual Studio Project file.

The problem I want to fix is:

  • You cannot set the project “Default namespace” in DBVA… yet
  • So, if you are using a base namespace like “mycompany.tech.project”, you have to build your ORM model with that in mind (I mean, first a mycompany package, then a tech package, and so on…)
  • When generating code, the folder structure includes all this “redundant” folders “mycompany”, “tech”, “project”. This can be easily fixed using the “Default namespace” setting in project properties. But they are some time-consuming tasks that you should do too. All details in the previous post.

Well, if you are like me and want to get rid of these extra folders :evil: , you can use my NAnt build file to fix that.

In addition, if you have some extra files you want to add to the generated .csproj file, or if you have coded some “partial” classes that extend the ORM base classes, you can tell this NAnt script also what files are, and then the ORM generated classes will be marked as partial as well :smiley:

The syntax is:
nant -buildfile:ORMfixes.build
-D:project=.csproj
-D:srcFolder=
-D:nsFolder=
-D:addFiles=

Example (using the previous noted base namespace):
nant -buildfile:ORMfixes.build
-D:project=myproject.csproj
-D:srcFolder=workspace\src
-D:nsFolder=mycompany\tech\project
-D:addFiles=addfiles.txt

addfiles.txt consisting of lines like this:
[;]

Example for addfiles.txt:
utils\classHelper.cs
pack1\class1.partial.cs;pack1\class1.cs

In this case:
:arrow: utils\classHelper.cs will be added to the .csproj file
:arrow: pack1\class1.partial.cs will be added to the .csproj file. Also, the item “” will be added to the file definition in .csproj, and set to class1.cs. Finally, pack1\class1.cs original ORM generated one will be marked as partial 8)

I hope that you find this useful. And please let me know if you find a bug in the build file!! :roll:

BTW, if you don’t know what NAnt is, you certainly should!!!
http://nant.sourceforge.net/

Happy coding with this excellent tool!!! (I mean, DB-VA!!!)

:smiley:
ORMfixes.build

Hi distansia,

Thank you for sharing your tips with us! :smiley: :smiley: :smiley:

Best regards,
Jick