[vs17.9] Ensure no IOException/SecurityException is thrown when setting console output/input encoding #9837
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #9833 to vs17.9
Fixes AB#1985518
Summary
PR #8503 added the custom language setting detection by env var
DOTNET_CLI_UI_LANGUAGE
as well as console output/input encoding settings on OSes that support UTF-8. This is also applied to FileLogger which is used by C++ Console project. Because devenv is a GUI process, setting console output/input encoding is not available and throws IOException. Then Building C++ Console project with VS fails withError: The handle is invalid
.To fix this, when setting console output/input encoding is not available catch IOException/SecurityException but do nothing.
Customer Impact
It blocks building C++ Console project with VS when setting env var
DOTNET_CLI_UI_LANGUAGE
.Regression?
Yes, building C++ Console project with VS 17.8.7 works well, but fails in 17.9.0.
Testing
Tested with VS 17.9.2 by deploying msbuild with this fix.
Risk
Low