Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.csproj File - Programmatic adding/deleting files

Tags:

c#

I've written a C# code generator to generate entities and related class files in our Ling-To-SQL application. The code generator needs to add/delete files in TFS and also add/delete them from a .csproj file so they are included or excluded properly in their respective projects.

I've figured out the TFS interaction but was curious as to the best or standard way of programmatically adding/removing files from .csproj files. Anyone have any experience with this?

Thanks - Randy

like image 363
Randy Minder Avatar asked Jan 05 '10 20:01

Randy Minder


3 Answers

.csproj files are just XML, and they conform to an XSD. Adding the new XML elements should be all it takes.

To find the XSD take a look at: Where can I find the schema (XSD) for a .csproj file?

like image 129
STW Avatar answered Sep 24 '22 04:09

STW


Another option is to use the Visual Studio automation model. From inside Visual Studio you can modify the project using macro code (VBA). This page on MSDN has links to the main automation libraries documentation.

Doing this, you could create a very slick integration. You could for instance have a Visual Studio macro that kicks off you code generation process and then adds the resulting files to the project.

like image 31
codeape Avatar answered Sep 21 '22 04:09

codeape


It's all XML. Load it into a DOM and have your way with it.

like image 20
Seva Alekseyev Avatar answered Sep 23 '22 04:09

Seva Alekseyev