Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Generate OpenAPI documents on build (dotnet build
) throws DirectoryNotFoundException
when application called Directory.SetCurrentDirectory(AppContext.BaseDirectory)
Expected Behavior
No exception thrown.
Steps To Reproduce
dotnet new webapi -n test-webapi
cd .\test-webapi\
dotnet add package Microsoft.Extensions.ApiDescription.Server
open Program.cs
and insert Directory.SetCurrentDirectory(AppContext.BaseDirectory)
at first line.
dotnet build
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.