Suppose I run msbuild as follows:
function Clean-Sln { param($sln) MSBuild.exe $sln /target:Clean } Clean-Sln c:\temp\SO.sln
In the Posh console, the output is in color. This is very convenient - you see the colors, just watching the exit. And, for example, not important messages are gray.
Question
I would like to add the ability to redirect it somewhere like this (simplified example):
function Clean-Sln { param($sln) MSBuild.exe $sln /target:Clean | Redirect-AccordingToRedirectionVariable } $global:Redirection = 'Console' Clean-Sln c:\temp\SO.sln $global:Redirection = 'TempFile' Clean-Sln c:\temp\Another.sln
- If I use the Console, cmdlet / function
Redirect-AccordingToRedirectionVariable should output msbuild messages with colors in the same way that the output was not sent through the channels. In other words, he must leave the way out as it is. - If I use "TempFile",
Redirect-AccordingToRedirectionVariable will store the output in a temporary file.
Is it possible? I think this is not so: | Or do you have any advice on how to achieve your goal?
Possible Solution:
if ($Redirection -eq 'Console) { MSBuild.exe $sln /target:Clean | Redirect-AccordingToRedirectionVariable } else { MSBuild.exe $sln /target:Clean | Out-File c:\temp.txt }
But if you assume that there may be many msbuild calls, this is not ideal.
Feel free to tell me a new suggestion on how to handle this;)
Any information on redirects / coloring / deleting is also welcome.
(The problem is not specific to msbuild, the problem concerns any application that writes color output)
source share