Where to store files for Azure function?

前端 未结 1 1842
时光取名叫无心
时光取名叫无心 2021-02-15 13:12

I have files that I reference from inside by C# code such as:

public static string Canonical()
{
    return File.ReadAllText(@"C:\\\\myapp\\\\" + "         


        
相关标签:
1条回答
  • 2021-02-15 13:34

    Yes, put the file at the root of Azure Function project and set its property Copy to Output Directory to Copy if newer. Use code below.

    public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log, ExecutionContext context)
    {
        var data = File.ReadAllText(context.FunctionAppDirectory+"/CanonicalMessage.xml");
    
        //etc
    }
    

    Check the doc for more details.

    If we need to add this file from anywhere locally, right click on Function project, Edit <FunctionProjectName>.csproj. Add Item below, relative or absolute path are both ok.

    <ItemGroup>
      <None Include="c:\\myapp\\CanonicalMessage.xml">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </None>
    </ItemGroup> 
    
    0 讨论(0)
提交回复
热议问题