问题描述
是否可以在 CI 服务器上的 MSBuild 任务中使用 Roslyn 进行编译之前修改源代码?我已经成功地在 VS 中做我想做的事,但我想知道在 VS 之外是否有可能.目前我正在研究工作区 API 和编译器 API,它们似乎是实现这一目标的正确工具,但我仍然不确定这是否可能?特别是我担心返回我对 MSBuild 所做的更改以使其继续工作.
Is it possible to modify source code before compilation using Roslyn within MSBuild task on CI server? I've succeeded to do what I want in VS but I wonder if it is possible outside VS. Currently I'm looking at Workspace APIs and Compiler APIs and they seem to be the right tool to achieve that, but I'm still not sure is it possible at all? In particular I'm concerned about returning changes that I've done to MSBuild back to allow it to continue its job.
推荐答案
这绝对是我们正在考虑的一个场景.今天有几个问题使它有点困难:
This is definitely a scenario that we are thinking of. Today there are a couple of problems that make it a bit difficult:
- 您无法使用 Workspace API 加载项目/解决方案,因为您已经在 msbuild 中.
- 要使用常规编译器 API,您需要自己构建一个编译器,这可能是一堆工作.
将来,我们希望提供从 csc/vbc 命令行字符串创建工作区",这将使这更容易.
In the future, we'd like to provide a "Create a workspace from a csc/vbc command line string", which would make this a lot easier.
看看 挂钩编译器(csc.exe 或 vbc.exe)本身 和 在 MS 构建任务中使用 Roslyn 的问题之前对此进行了一些讨论.
Take a look at Hooking into the compiler (csc.exe or vbc.exe) itself and Problem with using Roslyn in a MS Build Task for some previous discussion on this.
这篇关于使用 Roslyn 进行编译时源代码修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!