views:

957

answers:

1

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.

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

Thanks Richard

+2  A: 

Given your restrictions I think you can do the following:

  1. Create custom task that accepts the list of cs files to adapt prior to compilation
  2. The custom task adapts the list of files received and creates them on disk
  3. The custom task sets the list of changed files on the output parameter
  4. The output of the task would replace the original cs files list
  5. The compilation is done against the changed files.

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

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

smink
Cool, I'm going to give it a try - thanks Jorge
ZeroBugBounce