3

I have a situation where I need to generate a bunch of C# code files in a prebuild step of a project and include the generated files into the current project for compilation. Is there a way to do this cleanly without having to muck with the project file every time the prebuild step is run?

My solution should work for both IDE based build and a Team Build based on MSBuild. Since both are MSBuild based, I suspect there won't be much difference; but wanted to call it out.

Any help is greatly appreciated, thanks!

2 Answers 2

2

One way to go would be to use Custom Tool like Linq 2 SQL does on dbml file with the MSLinqToSQLGenerator Tool. But I don't think custom tool work with MSBuild.

Developing a Visual Studio Custom Tool

Sign up to request clarification or add additional context in comments.

2 Comments

I would be generating these files from a DLL; and I don't know how many of them would be generated before hand. Otherwise I could use placeholders or custom tools on some other definition files.
Somebody suggested to use a custom tool and modify the MSBuild project definition by writing a custom task that generates these files and includes them into the project during compile time. At this point that looks like a viable alternative. I will need a lot of time to put all of that together though. So won't have an immediate way to verify that. For this time, I consider this as answered. Thanks all for great answers.
-1

I have a project like this. The previous developer just added the current copies of the files, now each time the project it built they get pulled in.

On the other hand, he didn't document this, so it wasn't at all obvious; I had to spend a bit of time figuring out what was going on. But I haven't had to modify the setup.

1 Comment

OK; in my case I don't know how many files I would need to generate before hand. That is the biggest hurdle that is stopping me. Otherwise I could use place holders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.