dotnet-getdocument invocation, improper path handling on Windows in Microsoft.Extensions.ApiDescription.Server.targets breaks build #59749
Labels
area-commandlinetools
Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI
feature-openapi
Is there an existing issue for this?
Describe the bug
The microsoft.extensions.apidescription.server NuGet in src\Tools\Extensions.ApiDescription.Server\src\build\Microsoft.Extensions.ApiDescription.Server.targets has an improper handling of directory separators when executing the dotnet-getdocument.dll tool on Windows.
This breaks the build on Windows, if the value of OpenApiDocumentsDirectory ends in a Linux-style directory separator (
/
)microsoft.extensions.apidescription.server NuGet version: 9.0.0
Thanks.
Expected Behavior
Build should behave the same on Windows and Linux.
Steps To Reproduce
Bug occurs when
<OpenApiDocumentsDirectory>../openapi/</OpenApiDocumentsDirectory>
in my .csprojWhere and why does the bug occur
File: src\Tools\Extensions.ApiDescription.Server\src\build\Microsoft.Extensions.ApiDescription.Server.targets
This trims the trailing separator if and only the separator already is a Windows-style backslash. If it is a Linux style /, nothing gets trimmed. the Linux style path
../openapi/
gets translated to a Windows style path by$([System.IO.Path]::GetFullPath
. This results in_DotNetGetDocumentOutputPath
containing a path with a trailing\
, which breaks the command line the target generates (because it results in\"
, escaping the closing"
).Exceptions (if any)
Proposed Fix:
in src\Tools\Extensions.ApiDescription.Server\src\build\Microsoft.Extensions.ApiDescription.Server.targets, the
.TrimEnd('\')
needs to go after the$([System.IO.Path]::GetFullPath('$(_DotNetGetDocumentOutputPath)'))
, because the latter translates / to \ on windows. Hence if the initial path ends with /, nothing gets trimmed, then GetFullPath translates the / to \ on windows, and the command line contains an escaped " (\"
)..NET Version
9.0.200-preview.0.24575.35
Anything else?
No response
The text was updated successfully, but these errors were encountered: