-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: getItem/getProperty output can contain unrelated junk #36694
Comments
Shouldn't the welcome message be printed to stderr instead? (see Line 322 in 5c2e1fe
|
Yes, I'd track this as a change to the SDK (though the suggestion to write results to a specified file is also good). The SDK historically hasn't been a good citizen with regards to polluting stdout, and we should make it better in that regard. |
The welcome and workload update messages are from e.g.
But that's not a practical workaround. The |
@jrdodds dotnet does have a verbosity flag that is generally used:
and the I would suggest that folks who want to have a clean scripting experience set those to help ensure consistency until we can get the SDK to have more consistent output. |
Thanks @baronfel. I had tested |
Team Triage: this output belongs to sdk repo. |
Fixing all the places that write to stdout will be a game of whack-a-mole...
|
I don't disagree, but I think it's a thing we should be aiming towards across the stack. |
I don't think I'll trust getItem/getProperty for scripting unless I can get the output written to a file, since any random number of things can write to stdout (in particular tasks can do whatever they want, including straight out calling Console.WriteLine, which is a fairly common debugging technique after all, and it would be quite annoying to have scripting output fail because someone (me!) accidentally left in a Console.WriteLine somewhere). |
+1 Besides other things garbling stdout, also from a use-case perspective, it is sometimes desired to let MSBuild show the usual output while also retrieving properties. |
For the For the If you combine |
Granted a task can call For |
Yes, I'm suggesting it is a feature that there is no implied The regular MSBuild stdout is useful to have, also when evaluating properties. |
What output are you expecting or looking for? There is no output during the evaluation phase at |
In my case, I'm invoking
and I'd like the default output to appear to show how the operation is progressing. |
Regarding writing values to files, every target in a project is an entry point. You can define a |
@tmds I assume you want to pipe the digest to another process? What if you used
|
I want the default output to appear on stdout so it is part of the CI log. |
It sounds like you shouldn't use Add a target that runs at the end of the publish. If you want the digest on stdout, use a As conceived and currently implemented, |
This is an intended use for It's actually literally the example used to demonstrate SDK project evaluation support: https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-8#cli-based-project-evaluation. |
Tom's right - a major reason for making the feature is to support tooling that can't always easily drive or extend the build via custom targets. At this very moment Aspire apps deploy to Azure via azd using this feature. |
So if you have a CI environment that doesn't support binary logs - you're screwed? (Apparently |
@baronfel as I mentioned earlier on this ticket, I'd like to be able to get the default standard output while also using the project evaluation. The solution is the same as for this bug report: be able to write the evaluation output to a separate file. |
dotnet/msbuild#3911 included a |
I've created dotnet/msbuild#9617. |
I'm hearing two proposals here:
Those both sound reasonable to me. The first one was something people had proposed when I was first working on get*, but no one could give me a convincing reason it was actually useful. The reasons given in this issue were more convincing to me, at least, so I wouldn't mind adding that to my todo list. Afterwards, I'll have to look to see at what point we log those first use messages relative to when we parse the command line. If we parse the command line first, I think it should be pretty easy to special case -get* such that that automatically turns on those flags. If we emit those messages first, that one might be tricky... Does that sound like a correct summary? |
FWIW I have a different thought on the issue. Legacy-wise MSBuild has had as output: errors and messages which have been mapped to stderr and stdout, respectively.
Instead of supporting passing output files to each of In a future release the default for 'messages' could be a bin log file and the default for 'results' could be stdout. |
For now, I'm not sure we can route other output to stderr by default as the default powershell in windows will treat any stderr output as an error in the command. We think minimum verbosity might be the way to achieve this where we require the consumer to specify -v:min and then exclude everything but the eval output. Thoughts on that potential option? |
I assume that
is a response to the question asked by @ltrzesniewski in November
To the point being made: The welcome message is not an error and Windows Powershell is not alone. It's just one example of the many programs on all supported OSs that will interpret anything/everything on stderr as an error. |
stderr is a very common sidebar communications channel for not-just-error information. clig.dev has some guidelines for its use:
This helps ensure that piping and reuse of command output is clean. It's a shame that Windows Powershell doesn't support this manner of programming, but it is the state of the world we live in. Purely for my own information I'd love to hear about other non-Windows-Powershell shells that interpret stderr in such a strict, non-standard way. |
If the desire is to follow clig.dev then perhaps all messages should go to stderr, stdout should be used for results from the get* switches, and there should be a compatibility mode switch for the legacy behavior. |
That is indeed my desired end state, but there's a lot of work involved in the meantime to audit and catalogue all of the stdout usage in the CLI today. |
Just for the record, MSBuild differentiates between red messages that go to stdout, yellow messages that go to stdout, and normal-colored messages that go to stdout. MSBuild hasn't historically put anything in stderr at all—that was actually a new feature from the change to permit get* switches to avoid clogging up stdout even if there are errors. |
Permit specifying output file for get* CLI switches Fixes half of dotnet/sdk#36694 Context Design question: Should SimpleErrorLogger be enabled if we're redirecting into a file? Should it be enabled whenever we aren't using TerminalLogger? The reason I ask is that it's the only thing that writes to stderr at the moment, so since I re-enabled normal loggers when writing to a file, that means I disabled SimpleErrorLogger, and now errors come through stdout (with no TerminalLogger) as MSBuild normally does things. I'm not convinced that's ideal... Changes Made Permit using -getResultOutputFile to redirect output from get* into a file. Example: dotnet msbuild foo.csproj -getProperty:Bar -getResultOutputFile:Biz.txt This writes the value of property Bar into Biz.txt. Testing New unit test ensuring that it can output relevant information to a file.
My wish came true (dotnet/msbuild#9640), so for me this can be closed now. |
Issue Description
getItem/getProperty output can contain unrelated junk
Steps to Reproduce
Expected Behavior
bin\Debug/net8.0/
Actual Behavior
Analysis
I've also gotten the "Workload updates are available. Run
dotnet workload list
for more information." message at the end in some cases (which I believe shows up once per day), and broke the json parsing I was trying to do.Ideally getItem/getProperty arguments would take another argument specifying the output path, because relying on stdout not containing any other random junk is unreliable, and quite unsuitable for scripting.
Versions & Configurations
$ dotnet --version
8.0.100-rc.2.23502.2
The text was updated successfully, but these errors were encountered: