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

Exec task trims leading whitespace in ConsoleToMsBuild #9668

Closed
rainersigwald opened this issue Jan 19, 2024 · 2 comments · Fixed by #9722
Closed

Exec task trims leading whitespace in ConsoleToMsBuild #9668

rainersigwald opened this issue Jan 19, 2024 · 2 comments · Fixed by #9722
Assignees
Labels
Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. backlog Priority:2 Work that is important, but not critical for the release task-exec triaged

Comments

@rainersigwald
Copy link
Member

Given leading.txt

line with no leading whitespace
    line with some leading whitespace

and a project that transforms it into Exec stdout:

<Project>
    <Target Name="Go">
        <Exec Command="type leading.txt"
              StandardOutputImportance="low"
              ConsoleToMsBuild="true">
            <Output TaskParameter="ConsoleOutput" ItemName="ConOut" />
        </Exec>

        <Message Importance="high" Text="--interactive @(ConOut)" />
    </Target>
</Project>

Exec is trimming leading whitespace

msbuild -bl
MSBuild version 17.10.0-preview-24067-01+f1448f158 for .NET Framework
--interactive line with no leading whitespace;line with some leading whitespace

Build succeeded in 0.1s

binlog viewer screenshot showing missing whitespace

@rainersigwald rainersigwald added Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. needs-triage Have yet to determine what bucket this goes in. task-exec labels Jan 19, 2024
@AR-May AR-May added Priority:2 Work that is important, but not critical for the release triaged backlog and removed needs-triage Have yet to determine what bucket this goes in. labels Jan 23, 2024
@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Jan 23, 2024

msbuild/src/Tasks/Exec.cs

Lines 411 to 413 in 195e7f5

if (ConsoleToMSBuild)
{
string trimmedTextLine = singleLine.Trim();

This reminds me that ReadLinesFromFile likewise trims spaces. I had attempted to use ReadLinesFromFile, ItemGroup, and WriteLinesToFile to remove a particular line from a Visual Studio sln file, but the loss of indentation made the result invalid.

string trimmedTextLine = textLine.Trim(charsToTrim);

@yuehuang010
Copy link
Contributor

Can you double check if putting them into an item would Trim too?

<ItemGroup>
<Text Include="   file.cs" />
<Text Include="file1.cs" />
</ItemGroup>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Tasks Issues impacting the tasks shipped in Microsoft.Build.Tasks.Core.dll. backlog Priority:2 Work that is important, but not critical for the release task-exec triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants