我在 Docker 容器 (Linux) 中访问 .NET Core 项目中的 CSV 文件时遇到问题,它在调试模式下工作正常,但在发布模式下工作正常(错误提示找不到文件)。任何想法可能有什么问题?该项目有一个名为“Data”的文件夹,其中包含 CSV 文件。
[Route("GetTestFile")]
[HttpGet]
public IActionResult GetTestFile()
{
var fileName = "testdata.csv";
var filePath = Path.Combine("Data", fileName);
return new FileContentResult(File.ReadAllBytes(filePath), "text/csv") { FileDownloadName = fileName };
}
Run Code Online (Sandbox Code Playgroud)
文件
FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY PVT_Matching_Algorithm/PVT_Matching_Algorithm.csproj PVT_Matching_Algorithm/
RUN dotnet restore PVT_Matching_Algorithm/PVT_Matching_Algorithm.csproj
COPY . .
WORKDIR /src/PVT_Matching_Algorithm
RUN dotnet build PVT_Matching_Algorithm.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish PVT_Matching_Algorithm.csproj …Run Code Online (Sandbox Code Playgroud)