使用Roslyn修改编译时的源代码 [英] Compile-time source code modification using Roslyn

查看:184
本文介绍了使用Roslyn修改编译时的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在CI服务器上的MSBuild任务中使用Roslyn在编译之前修改源代码?我已经成功地在VS中完成了我想做的事情,但是我想知道在VS之外是否有可能.目前,我正在研究Workspace API和Compiler 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:

  1. 由于您已经在msbuild中,因此无法使用Workspace API加载项目/解决方案.
  2. 要使用常规的编译器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)

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修改编译时的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆