I´m trying to output a xml file that I have in my .net core api project and then accessing that file later on in the code.
I have this code in my project.json to output the xml
"buildOptions": {
"emitEntryPoint": true,
"copyToOutput": "myfile.xml"
"preserveCompilationContext": true
}
And then I try to access it like this
public Startup(IHostingEnvironment env)
{
var path = env.ContentRootPath;
var filepath = Path.Combine(path, "myfile.xml");
var doc = new XmlDocument();
doc.Load(fileName); //throws error
}
But when I run this in Azure I get this error
FileNotFoundException - Could not find file 'D:\home\site\wwwroot\myfile.xml'.
I have tried every version of e.g this answer but with no luck.
UPDATE 1
Here is my Main method in Program.cs
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
I tried to find the xml file by browsing (with Kudu Service) every thinkable folder so I´m thinking that the xml file doesn´t get build out https://myvsts.scm.azurewebsites.net/api/vfs/site/wwwroot/
UPDATE 2
I found out that copyToOutput works just fine locally but not on azure. I implemented this to browse the folder and my xml file does not show up until I right click it and press publish! Its like the project publish doesn´t pick it up...