简体   繁体   中英

How to automatically include generated source files into a C# project in Visual Studio?

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!

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM