Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding inherited tasks in MSBuild

I have an inherited MSBuild script, which calls targets that I am not allowed to change. However, some of these targets call methods that are currently too verbose in the output window - for example, the <Copy> task is used so much that it's output is draining any other relevant message.

Since I don't have access to the target calling <Copy>, I can't switch it to something less verbose. I've played around with the /verbosity switch, but minimal gives me too little output, and normal gives me too much.

Is there any other way I can affect the verbosity of <Copy> specifically, or of MSBuild in general?

like image 931
Tomas Aschan Avatar asked Jan 17 '26 00:01

Tomas Aschan


1 Answers

You can create your own logger. It is a little bit involved, but basically allows you to fine tune exactly what messages you want to see. The easiest thing to do would be to override the default logger.

Another easier option is to override the Copy task. Create your own custom task named Copy, and refer to it with a UsingTask declaration. This declaration needs to appear first, I think (can't remember if task override is first-one-wins or last-one-wins). Again, you can subclass the default Copy task in the MSBuild assembly and override Execute, or just roll your own. In the task, you can adjust the verbosity level associated with various messages by calling Log.LogMessage and supplying the level of each message, so you can control which command line verbosity they will appear with.

like image 166
Brian Kretzler Avatar answered Jan 19 '26 20:01

Brian Kretzler