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 from assembly Microsoft.Build.Tasks.Core fails with special characters in user folder. #6637

Closed
Baklap4 opened this issue Jun 29, 2021 · 3 comments
Assignees
Labels
bug initial-investigation Perform initial investigation, apply untriaged label when done. triaged

Comments

@Baklap4
Copy link

Baklap4 commented Jun 29, 2021

Issue Description

We've created a Pre-Build event which runs a command to install/update webcompiler. However this fails with the message:

Target ToolRestore:
  Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
  Task "Exec"
    dotnet tool update Excubo.WebCompiler
    'C:\Users\SomeUser' is not recognized as an internal or external command,
    operable program or batch file.
    C:\git\projects\project-x\src\ProjectX\ProjectX.csproj(78,9): error MSB3073: The command "dotnet tool update Excubo.WebCompiler" exited with code 1.
  Done executing task "Exec" -- FAILED.

Steps to Reproduce

  1. Create a local Windows User with a special character in it: SomeUser(Company)
  2. Login to that user
  3. Create new Console Project (.NET 5)
  4. Add a prebuild task
<Target Name="ToolRestore" BeforeTargets="PreBuildEvent">
    <Exec Command="dotnet tool update Excubo.WebCompiler" StandardOutputImportance="high" ContinueOnError="false" IgnoreExitCode="false" LogStandardErrorAsError="false" />
</Target>
  1. Add a manifest file: dotnet new tool-manifest
  2. Build project.

Expected Behavior

The project builds without errors.

Actual Behavior

The project fails to run the command in the target ToolRestore.
The output is:

Target ToolRestore:
  Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
  Task "Exec"
    dotnet tool update Excubo.WebCompiler
    'C:\Users\SomeUser' is not recognized as an internal or external command,
    operable program or batch file.
    C:\git\projects\project-x\src\ProjectX\ProjectX.csproj(78,9): error MSB3073: The command "dotnet tool update Excubo.WebCompiler" exited with code 1.
  Done executing task "Exec" -- FAILED.

Analysis

Our user folder has a special character in it:
C:/Users/SomeUser(Company)
Since the tools are collected within your %APPDATA% folder it cannot find these and we're left with the message:
'C:\Users\SomeUser' is not recognized as an internal or external command, operable program or batch file. not the missing (

We've excluded the tool in question Excubo.WebCompiler as it also occurs with many other tools.

Example program

Made a sample project for demonstrating purposes
PreBuildEvent.zip

Versions & Configurations

PS C:\git\projects\project-x> msbuild -version
Microsoft (R) Build Engine version 16.10.2+857e5a733 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.10.2.30804

We're using Windows 10 build 19043.1052
and have .NET 5 installed

PS C:\git\projects\project-x> dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.301
 Commit:    ef17233f86

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.301\

Host (useful for support):
  Version: 5.0.7
  Commit:  556582d964

.NET SDKs installed:
  3.1.410 [C:\Program Files\dotnet\sdk]
  5.0.104 [C:\Program Files\dotnet\sdk]
  5.0.204 [C:\Program Files\dotnet\sdk]
  5.0.301 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Extra info

We've found some previous encounters with this bug here:
https://developercommunity.visualstudio.com/t/nuget-bug-in-vs155/160750
Do note the exact issue in this link is the repository is at a special path. Our issue is about running the prebuild task (from visual studio) where it uses something from %APPDATA% but since that path contains a special character ( it breaks.

We've also found another previous encounter:
https://developercommunity.visualstudio.com/t/post-build-event-fails-when-parentheses-in-windows/574866

@Baklap4 Baklap4 added bug needs-triage Have yet to determine what bucket this goes in. labels Jun 29, 2021
@benvillalobos benvillalobos self-assigned this Jun 30, 2021
@benvillalobos benvillalobos added initial-investigation Perform initial investigation, apply untriaged label when done. and removed needs-triage Have yet to determine what bucket this goes in. labels Jun 30, 2021
@benvillalobos
Copy link
Member

We recently took a change that should have prevented issues like this. Did this work on any previous version of MSBuild?

@Baklap4
Copy link
Author

Baklap4 commented Jun 30, 2021

Did this work on any previous version of MSBuild?

I've stumbled upon this since i started working at another company since december 2020. Explicitly a previous version i cannot say

We recently took a change that should have prevented issues like this

Is the change already released in a newer version? If yes i'm eager to try it out as it helps us save time by reconfiguring up to 5 pc's removing the ( and ) from the user' folder

@Baklap4
Copy link
Author

Baklap4 commented Jun 30, 2021

Sooo since this issue didn't occur anymore at my laptop since i changed my userfolder' name. I asked my co-workers to test it out. Some of them were still on 16.9.x

They indeed got errors trying to build this project. I told them to update and print me the msbuild versions they were using and after updating they got at version 16.10.2+857e5a733 (the latest release).
With the updates installed they successfully built the project so I think this issue can be closed and marked fixed in mentioned PR.

Thanks for pointing to the PR and the prompt result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug initial-investigation Perform initial investigation, apply untriaged label when done. triaged
Projects
None yet
Development

No branches or pull requests

3 participants