'In ASP.NET Core how do I read an XML file that is outside the web root?

In my previous question the solution to my problem involved having to write an XML configuration file and then read it at startup: How to stop double redirect on https and www in ASP.NET Core 6?

In Program.cs I ended up with this:

app.UseRewriter(new RewriteOptions().AddIISUrlRewrite( app.Environment.WebRootFileProvider, "IISUrlRewrite.xml") );

Which works fine if the XML file is in wwwroot. I tried moving the XML file to the Content (Project) Root but nothing I change in the .csproj will cause it to just copy that file over to the server when I do a web deploy. It feels like the XML file is being compiled into the code.

I'd really like the file to live in a "Resources" folder and access it that way somehow.

Is there a way I can do that? Make a folder called Resources and access it through the API somehow? I need to get a StreamReader object to pass to the AddIISUrlRewrite function.

What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source