Generate OpenAPI documents on build throws DirectoryNotFoundException when application calls 'Directory.SetCurrentDirectory(AppContext.BaseDirectory)' #60987
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
Generate OpenAPI documents on build (
dotnet build
) throwsDirectoryNotFoundException
when application calledDirectory.SetCurrentDirectory(AppContext.BaseDirectory)
Expected Behavior
No exception thrown.
Steps To Reproduce
open
Program.cs
and insertDirectory.SetCurrentDirectory(AppContext.BaseDirectory)
at first line.Exceptions (if any)
test-webapi 失败,出现 9 错误 (1.3) → bin\Debug\net9.0\test-webapi.dll
C:\Users\xxxxx.nuget\packages\microsoft.extensions.apidescription.server\9.0.3\build\Microsoft.Extensions.ApiDescription.Server.targets(68,5): error : System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\xxxxxx\source\repos\xxx\test-webapi\bin\Debug\net9.0\obj\test-webapi.OpenApiFiles.cache'.
.NET Version
9.0.200
Anything else?
Backgrounds:
I have a webapi that run as windows services and access Sqlite database. The connection string is configured in appsettings.json like
Data Source=./mydb.db
.The database file is always stored in C:/Windows/System32 due to application is running under system process.
Call
Directory.SetCurrentDirectory(AppContext.BaseDirectory)
so that database file willbe saved at application content directory.The text was updated successfully, but these errors were encountered: