簡體   English   中英

默認的Azure Function應用程序基本路徑D:\\ home \\ site \\ wwwroot Azure Function 2.x

[英]Default Azure Function app base path D:\home\site\wwwroot Azure Function 2.x

當前,默認情況下,Azure函數的基本路徑設置為“ D:\\ home \\ site \\ wwwroot”。 例如,發布時,VS將應用程序上傳到此文件夾。

我需要從該文件夾中讀取配置文件。 我們有一個問題, 通過構造函數的依賴注入ExecutionContext為空

如果將來更改路徑,則設置新的環境變量可能會導致問題。

我的問題是,我該如何使用可靠且穩定的,通過構造函數與DI配合使用的應用程序基本路徑。

Azure Function 2.x

VS 2017

您可以使用function.json獲取配置密鑰對。 例如:

System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);

在function.json中,您可以像這樣: “ mykey”:“ myvalue”

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.24",
  "configurationSource": "attributes",
  "bindings": [
  {
      "direction":"in",
      "type": "timerTrigger",
      "useMonitor": true,
      "runOnStartup": false,
      "name": "myTimer",
      "mykey": "myvalue"
  }
  ],
      "disabled": false,
      "scriptFile": "../bin/**.dll",
      "entryPoint": "**.Run"
} 

有一個指向home目錄的環境變量。 這不會改變,因為包括功能應用程序在內的許多服務都依賴它。 下面是函數運行時如何在Azure環境中獲取它的方法。

    string home = GetEnvironmentVariable("HOME");
    Path = System.IO.Path.Combine(home, "site", "wwwroot");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM