Pablo
Pablo

Reputation: 2301

ASP.NET Core, Could not find file. How Can I publish it?

I have found many questions like this, but I'm still having problems to get a "static" file.

The task should be simple. Just get a cshtml file content. A file that it's already in the project. But it's taking forever to figure it out.

This is the error that I'm getting (only when in production)

Could not find file 'D:\home\site\wwwroot\AppData\template.cshtml'.

Looking into the 'D:\home\site\wwwroot' folder, indeed the 'AppData' doesn't exist. But then how can I publish the AppData and its files?

This is how I'm getting the file

string contentRootPath = webHostEnvironment.ContentRootPath;
return $"{contentRootPath}/AppData/{filename}";

This is inside .csproj

<Folder Include="AppData\" />

To publish the project I'm using DevOps Azure. Is there any configuration that I'm missing?

Upvotes: 0

Views: 949

Answers (1)

Pablo
Pablo

Reputation: 2301

I don't know if this is the right approach, but it's working (for now).

In DevOps/Pipelines/MyMypeline/Tasks, I add Copy files Task.

  • Source Folder: MyProject/AppData
  • Target Folder: $(Agent.TempDirectory)\WebAppContent\AppData

The next task (Archive files) it was already set. So in resume, the pipeline will get the files from AppData and add in the same place where the solution was build. And the other task will zip all. Than another task (Azure Web App) will sent the zip to my AppService.

I still have to test when do the swipe from dev to prod, but for now that's it.

Upvotes: 0

Related Questions