I’m using CodeSmith on my current project and I’m trying to figure out an issue. For my CodeSmith project (.csp) I can select an option to have it automatically add all generated files to the current project (.csproj). But I want to be able to add the output to multiple projects (.csproj). Is there an option inside of CodeSmith to allow this? Or is there a good way to programmatically do that?
Thanks.
I was unable to figure out a way to make CodeSmith handle this issue automatically, so I ended up writing a custom method in the Code Behind file to handle this.
A few notes:
– The proj files are XML, and as thus fairly easy to edit, but the actual “ItemGroup” node that holds the list of files that are included in the project isn’t actually labeled in any special way. I ended up picking the “ItemGroup” node that has “Contains” child nodes, but there might be a better way to determine which you should use.
– I recommend doing all the proj file changes at once, instead of as each file is created/updated. Otherwise if you launch the generation from Visual Studio, you might get a flood of “This item has changed, would you like to reload”
– If your files are under source control (they are, right?!), you’re going to need to handle checking files out and adding them to source control along with editing the proj files.
Here is (more or less) the code I used to add a file to the project: