VS2010 的自定义构建
我需要使用外部命令行编译器编译解决方案中的一些文件,并将其输出(cs 文件)传递到 C# 编译器的输入,以便它将它们构建到生成的程序集中。建议实现此任务的方法。
I need to compile some files in my solution with an external command line compiler, and pass it's output (cs files) to the input of the C# compiler, so it will build them into the resulting assembly. Suggest approaches to achieve this task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前也遇到过同样的问题。最简单的方法是将输出文件包含在项目中,并从预构建事件命令行设置中调用生成器。这种技术存在很多问题,它对集成源代码控制造成严重破坏,如果您的生成器动态创建文件,它将无法工作。有多种方法可以解决这个问题,在覆盖它们之前比较生成器中的文件,以便只有更改才会导致覆盖,并将文件连接到例如具有已知名称文件的单个 .cs 中。恕我直言,这些都不有趣或令人满意。
如果可能的话,我建议您考虑使用 T4 来实现此目的。你没有说外部发电机是否是你的,但如果是的话,转换起来应该不会太难。与外部链接的工具相比,T4 更干净、更清晰、更容易维护。
I've run across this same problem before. The easist thing to do is to include the output file(s) in your project and call the generator from the pre-build event command line setting. There are many problems with this technique, it wrecks havoc on integrated source control and if your generator creates files dynamically it won't work. There are ways to get around this, compare the files from the generator before overwriting them so that only changes result in overwrites, and concat the files into a single .cs with a known name file for example. None of these are fun or satifactory IMHO.
I'd recommend if at all possible you look at using using T4 for this. You don't say whether the external generator is yours or not but if it is it shouldn't be too hard to convert. It is much cleaner, clearer, and easier to maintain the T4 than an externally linked tool.
您可以使用项目->设置->构建事件 ->预构建事件生成您的 CS 文件,然后确保您的 CS 文件包含在您的项目中并且它应该可以正常构建。
You can use Project -> Settings -> Build Events -> Pre-build event to generate your CS file and then just make sure your CS file is included in your project and it should build just fine.