Skip to content

[Bug]: Illegal characters in path. #8762

@EdLichtman

Description

@EdLichtman

Issue Description

When I run MsBuild standalone from Visual studio, I get the following error:

MSBUILD : error : This is an unhandled exception in MSBuild -- PLEASE UPVOTE AN EXISTING ISSUE OR FILE A NEW ONE AT https://aka.ms/msbuild/unhandled. [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :     System.ArgumentException: Illegal characters in path. [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at System.IO.LongPathHelper.Normalize(String path, UInt32 maxPathLength, Boolean checkInvalidCharacters, Boolean expandShortPaths) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at System.IO.Path.GetFullPathInternal(String path) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Shared.FileUtilities.MakeRelative(String basePath, String path) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.ThrowForImportedProjectWithSearchPathsNotFound(ProjectImportPathMatch searchPathMatch, ProjectImportElement importElement) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.Execution.ProjectInstance.Initialize(ProjectRootElement xml, IDictionary`2 globalProperties, String explicitToolsVersion, String explicitSubToolsetVersion, Int32 visualStudioVersionFromSolution, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, Nullable`1 projectLoadSettings, EvaluationContext evaluationContext) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.BackEnd.BuildRequestConfiguration.<>c__DisplayClass60_0.<LoadProjectIntoConfiguration>b__0() [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.BackEnd.BuildRequestConfiguration.InitializeProject(BuildParameters buildParameters, Func`1 loadProjectFromFile) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.<BuildProject>d__68.MoveNext() [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error : --- End of stack trace from previous location where exception was thrown --- [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]
                 [exec] MSBUILD : error :    at Microsoft.Build.BackEnd.RequestBuilder.<BuildAndReport>d__59.MoveNext() [C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.WebHost\ApiGateway.WebHost.csproj]

That said, I have modified the Path to remove certain identifying information. If you need the original path, let me know and we can reach out in a less public setting. All of the characters that were removed though were Alphanumeric, or were Periods (.)

It took a couple of weeks but we narrowed down the issue to being due to the following property:

<VSToolsPath>
  $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
</VSToolsPath>

instead of
<VSToolsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

Now the bug is about throwing an intuitive error with information , instead of the incredibly cryptic message above.

Steps to Reproduce

This is the MSBuild command line invocation:
"msbuild.exe" /nologo /verbosity:detailed /maxCpuCount /nodeReuse:False /property:Configuration=debug;TreatWarningsAsErrors=true /property:platform="Any CPU" /property:ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch=None /property:CodeAnalysisRuleSetDirectories="C:\Source\root\core-team-main\Tools\3rdParty\Microsoft\Rule Sets" /property:BuildProjectReferences=true /property:NoWarn="SA1652;SA0001" /target:build C:\Source\root\core-team-main\src\ApiGateway\ApiGateway.sln

I cannot produce a minimal sample project because when I do the issue is not present. I can provide the csproj file once I know to whom this issue is assigned though.

Expected Behavior

I can compile with a line break in my Property Override, OR, I can be told exactly what is wrong so I can fix it.

Actual Behavior

I am given an incredibly cryptic error and spend a substantial amount of time trying to figure out what's wrong.

Analysis

we narrowed down the issue to being due to the following property:

<VSToolsPath>
  $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
</VSToolsPath>

instead of
<VSToolsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

When I create a brand new project I don't seem to have this issue.

Versions & Configurations

MSBuild version 17.5.1+f6fdcf537 for .NET Framework
17.5.1.16304

Metadata

Metadata

Assignees

Labels

Area: DebuggabilityIssues impacting the diagnosability of builds, including logging and clearer error messages.Good First IssueSelf-contained issues good for first-time contributors.bugtriaged

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions