Skip to content
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

Permit specifying output file #9640

Merged
merged 7 commits into from
Feb 28, 2024
Merged

Conversation

Forgind
Copy link
Member

@Forgind Forgind commented Jan 12, 2024

For get* CLI switches

Fixes #

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

I tried using this, and it failed to load my test project because it was trying to include $(MonoAndroidResourcePrefix)(various), and MonoAndroidResourcePrefix was not defined. That doesn't feel like it's related to my change, but it's hard for me to firmly state that this works when 100% of my tests have failed 🙃

I tried again today, and the error mysteriously disappeared. It failed until I added Flush, but now it seems to work properly.

Notes

src/MSBuild/XMake.cs Outdated Show resolved Hide resolved
src/MSBuild/XMake.cs Outdated Show resolved Hide resolved
Copy link
Member

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
Not 100% sure about the 'side effect' of enabling logging to console, but I guess otherwise this change wouldn't have much sense anyways (as one could just redirect).

@tmds
Copy link
Member

tmds commented Feb 20, 2024

Looking forward to have this in an SDK near me!

Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but this should not be merged without test coverage. Please add a test.

Also, ideally the new command line switch would be added to -help output but -getProperty and such are still missing from it so we can handle it as part of #9710.

@Forgind
Copy link
Member Author

Forgind commented Feb 23, 2024

FYI, I called my commit 'Start on test', but that was just because I don't have the components to build on this laptop, so I didn't run it locally before pushing, but it seems to have built and passed 🙂

Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

src/MSBuild.UnitTests/XMake_Tests.cs Outdated Show resolved Hide resolved
@Forgind Forgind merged commit 277b7b4 into dotnet:main Feb 28, 2024
8 checks passed
@Forgind Forgind deleted the add-output-to-file-option branch February 28, 2024 17:15
@tmds
Copy link
Member

tmds commented Apr 11, 2024

@Forgind is this a .NET 9 feature only? Or is it expected to become available in a .NET 8 SDK band?

@rainersigwald
Copy link
Member

@tmds it'll be in MSBuild 17.10/SDK 8.0.3xx.

@VAllens
Copy link

VAllens commented Apr 12, 2024

Good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants