如何扩展msbuild以在.cs文件上运行自定义预处理器?

时间:2022-08-22 21:21:52

I have a custom program which preprocesses a C# file and generates a new C# file as output. I would like to invoke this from msbuild on each of the C# files in the project, then compile the output files instead of the original C# files. How would I go about this?

我有一个自定义程序,它预处理一个C#文件并生成一个新的C#文件作为输出。我想从msbuild在项目中的每个C#文件上调用它,然后编译输出文件而不是原始的C#文件。我怎么会这样呢?

3 个解决方案

#1


1  

You might want to look into using the "custom tool" code generation techniques in Visual Studio; there's an article about it on CodeProject

您可能希望在Visual Studio中使用“自定义工具”代码生成技术;在CodeProject上有一篇关于它的文章

#2


1  

I'm not sure if there is an easy way to perform it with default msbuild tasks. But you can create your own task to do whatever you want:

我不确定是否有一种简单的方法可以使用默认的msbuild任务来执行它。但是你可以创建自己的任务来做任何你想做的事情:

How To: Implementing Custom Tasks - Part I

如何:实现自定义任务 - 第一部分

Also you can search for suitable tasks at "MSBuild community tasks" site.

您还可以在“MSBuild社区任务”站点搜索合适的任务。

#3


0  

If your custom program is an executable the easiest way would be to call the executable with Exec:

如果您的自定义程序是可执行文件,最简单的方法是使用Exec调用可执行文件:

<Exec Command="your executable" />

I would recommend writing a custom MSBuild task though. You can look at the SDC Tasks for samples on how to do it.

我建议编写一个自定义的MSBuild任务。您可以查看SDC任务以获取有关如何执行此操作的示例。

#1


1  

You might want to look into using the "custom tool" code generation techniques in Visual Studio; there's an article about it on CodeProject

您可能希望在Visual Studio中使用“自定义工具”代码生成技术;在CodeProject上有一篇关于它的文章

#2


1  

I'm not sure if there is an easy way to perform it with default msbuild tasks. But you can create your own task to do whatever you want:

我不确定是否有一种简单的方法可以使用默认的msbuild任务来执行它。但是你可以创建自己的任务来做任何你想做的事情:

How To: Implementing Custom Tasks - Part I

如何:实现自定义任务 - 第一部分

Also you can search for suitable tasks at "MSBuild community tasks" site.

您还可以在“MSBuild社区任务”站点搜索合适的任务。

#3


0  

If your custom program is an executable the easiest way would be to call the executable with Exec:

如果您的自定义程序是可执行文件,最简单的方法是使用Exec调用可执行文件:

<Exec Command="your executable" />

I would recommend writing a custom MSBuild task though. You can look at the SDC Tasks for samples on how to do it.

我建议编写一个自定义的MSBuild任务。您可以查看SDC任务以获取有关如何执行此操作的示例。