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
.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?
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.
It's all XML. Load it into a DOM and have your way with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With