创建自定义的MSBuild任务之前修改C#code *编译自定义、任务、MSBuild、code

2023-09-03 17:02:16 作者:CALL ME BABY-叫我宝贝

我想创建一个自定义的MSBuild任务是改变了我的.cs文件,它们是由csc.exe的编译之前(但是,当然,这并不改变他们在的地方 - 我不想实际的源文件的感动) 。我知道PostSharp和.NET等AOP框架,他们不是为这个特定的项目的选项,再加上我想了解如何做到这一点。

I want to create a custom MSBuild task that changes my .cs files before they are compiled by csc.exe (but, of course, that doesn't modify them in place - I don't want actual source files touched). I am aware of PostSharp and other AOP frameworks for .NET and they are not an option for this particular project, plus I'd like to learn how to do this.

什么precisely做我必须做的就是这个工作?

What precisely do I have to do to get this to work?

谢谢 理查德

推荐答案

鉴于你的限制,我认为你可以做到以下几点:

Given your restrictions I think you can do the following:

创建一个接受的CS文件列表前,以适应自定义任务编译 在自定义任务相适应接收的文件的列表,并在磁盘上创建它们 在自定义任务设置更改文件的输出参数列表 任务将代替原来的CS文件列表输出 在编译完成对修改过的文件。

第4步可确保最终被编译的文件是由您自定义任务改变的。

The step 4 ensures that the files that are eventually compiled are the ones that were changed by your custom task.

您将在很大程度上依赖于ITaskItem接口的工作。

You will heavily rely on the ITaskItem interface for the job.