<i id='yo1ok'><tr id='yo1ok'><dt id='yo1ok'><q id='yo1ok'><span id='yo1ok'><b id='yo1ok'><form id='yo1ok'><ins id='yo1ok'></ins><ul id='yo1ok'></ul><sub id='yo1ok'></sub></form><legend id='yo1ok'></legend><bdo id='yo1ok'><pre id='yo1ok'><center id='yo1ok'></center></pre></bdo></b><th id='yo1ok'></th></span></q></dt></tr></i><div id='yo1ok'><tfoot id='yo1ok'></tfoot><dl id='yo1ok'><fieldset id='yo1ok'></fieldset></dl></div>

      <legend id='yo1ok'><style id='yo1ok'><dir id='yo1ok'><q id='yo1ok'></q></dir></style></legend>
    1. <small id='yo1ok'></small><noframes id='yo1ok'>

        <bdo id='yo1ok'></bdo><ul id='yo1ok'></ul>
        <tfoot id='yo1ok'></tfoot>

        Azure Functions 不发布 appsettings.prod.json 文件

        Azure Functions don#39;t publish appsettings.prod.json file(Azure Functions 不发布 appsettings.prod.json 文件)
            <tbody id='W8fiq'></tbody>
            <bdo id='W8fiq'></bdo><ul id='W8fiq'></ul>

              <tfoot id='W8fiq'></tfoot>

              • <i id='W8fiq'><tr id='W8fiq'><dt id='W8fiq'><q id='W8fiq'><span id='W8fiq'><b id='W8fiq'><form id='W8fiq'><ins id='W8fiq'></ins><ul id='W8fiq'></ul><sub id='W8fiq'></sub></form><legend id='W8fiq'></legend><bdo id='W8fiq'><pre id='W8fiq'><center id='W8fiq'></center></pre></bdo></b><th id='W8fiq'></th></span></q></dt></tr></i><div id='W8fiq'><tfoot id='W8fiq'></tfoot><dl id='W8fiq'><fieldset id='W8fiq'></fieldset></dl></div>

              • <legend id='W8fiq'><style id='W8fiq'><dir id='W8fiq'><q id='W8fiq'></q></dir></style></legend>
              • <small id='W8fiq'></small><noframes id='W8fiq'>

                  本文介绍了Azure Functions 不发布 appsettings.prod.json 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在将我的 .NET Core 控制台应用程序部署到 Azure Function,因此我正在使用 appsettings.json 文件,因为我们现在没有时间将其更改为 local.settings.json 文件.

                  I'm deploying my .NET Core Console app to Azure Function, and for this reason I'm using appsettings.json files because we don't have time to change it to local.settings.json file right now.

                  通过 VSCode 在 Azure Function 中发布应用后,/azure-functions-host/ 目录中存在 appsettings.json 和 appsettings.dev.json,但 appsettings.prod.json 中不存在.

                  After publishing the app in Azure Function through VSCode, appsettings.json and appsettings.dev.json exists in the /azure-functions-host/ directory, but not the appsettings.prod.json.

                  我在依赖项目中有这些复制属性:

                  I have these copy properties in a dependent project:

                  <ItemGroup>
                      <None Include="....appsettings.prod.json">
                        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
                      </None>
                      <None Include="....appsettings.dev.json" Condition=" '$(Configuration)' == 'Debug' ">
                        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
                      </None>
                      <None Include="....appsettings.json">
                        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
                      </None>
                  </ItemGroup>
                  

                  例外:

                  The configuration file 'appsettings.prod.json' was not found and is not optional. The physical path is '/azure-functions-host/appsettings.prod.json'.
                     at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
                     at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
                     at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
                     at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
                     at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
                     at DataImoveis.Setup.SetupConfig.LoadConfig(IServiceCollection service) in /mnt/d/Cloud/dev/src/DataImoveis.Setup/SetupConfig.cs:line 26
                  

                  我的 LoadConfig 函数:

                  My LoadConfig function:

                          public static void LoadConfig(IServiceCollection service)
                          {
                              string env = "dev";
                  
                              if (!checkFunctionEnvironment(ref env))
                              {
                                  checkIfRelease(ref env);
                              }
                  
                              var currentPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                              var config = new ConfigurationBuilder()
                                  .SetBasePath(currentPath)
                                  .AddJsonFile(
                                      "appsettings.json",
                                      optional: false,
                                      reloadOnChange: true
                                  )
                                  .AddJsonFile(
                                      $"appsettings.{env}.json",
                                      optional: false,
                                      reloadOnChange: true
                                  );
                              service
                                  .AddDefaultAWSOptions(config.Build().GetAWSOptions())
                                  .Configure<Settings>(config.Build());
                          }
                  

                  这是怎么回事?为什么只是这个文件没有发布?我已经尝试了很多东西,比如 CopyToPublishDirectory = Always 选项和其他东西.

                  What this happens? Why just this file isn't published? I've tried a lot of things like CopyToPublishDirectory = Always option and other stuff.

                  我已经在图像/主机中搜索了 appsettings.prod.json 文件,但没有找到.

                  I've searched for the appsettings.prod.json file inside of the image/host and I haven't found it.

                  推荐答案

                  ItemGroup中使用ResolvedFileToPublish可以解决你的问题.

                  以下是我的测试步骤.

                  Use ResolvedFileToPublish in ItemGroup can solve your issues.

                  Below is my test steps.

                  第 1 步.

                  我在本地创建 appsettings.dev.jsonappsettings.prod.json,如下所示.

                  I create appsettings.dev.json and appsettings.prod.json in my local like below.

                  第 2 步.

                  在您的 <projectname>.csproj 文件中添加以下设置.

                  Add below settings in your <projectname>.csproj file.

                  示例代码.

                  <ItemGroup>
                      <ResolvedFileToPublish Include="azure-functions-host/appsettings.prod.json">
                      <RelativePath>azure-functions-host/appsettings.prod.json</RelativePath>
                      </ResolvedFileToPublish>
                      <ResolvedFileToPublish Include="azure-functions-host/appsettings.dev.json">
                      <RelativePath>azure-functions-host/appsettings.dev.json</RelativePath>
                      </ResolvedFileToPublish>
                  </ItemGroup>
                  

                  第 3 步.

                  检查 scm 站点中的文件.

                  Check files in scm site.

                  第 4 步.

                  检查我的测试函数网址.

                  Check my test function url.

                  我的测试代码.

                      [FunctionName("HttpTriggerCSharp1")]
                      public static async Task<IActionResult> Run(
                          [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
                          ILogger log)
                      {
                          log.LogInformation("C# HTTP trigger function processed a request.");
                  
                          ///////////////////////////////////////////////////////////////////////
                          bool isLocal = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"));
                          var jsonString=string.Empty;
                          if(isLocal){
                              jsonString = File.ReadAllText(Path.Combine(@"C:homesitewwwrootazure-functions-host","appsettings.dev.json"));
                          }else{
                              try
                              {
                                  jsonString = File.ReadAllText(Path.Combine(@"C:homesitewwwrootazure-functions-host","appsettings.prod.json"));
                              }
                              catch (System.Exception e)
                              {
                                  jsonString=e.ToString();
                                  throw;
                              }
                              
                          }
                          
                          string response = isLocal ? "Function is running on local environment." : "Function is running on Azure.";
                  
                          ///////////////////////////////////////////////////////////////////////
                  
                          return new OkObjectResult(jsonString);
                      }
                  

                  这篇关于Azure Functions 不发布 appsettings.prod.json 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                      <small id='iKbia'></small><noframes id='iKbia'>

                    • <tfoot id='iKbia'></tfoot>
                        <bdo id='iKbia'></bdo><ul id='iKbia'></ul>
                          <tbody id='iKbia'></tbody>
                      • <legend id='iKbia'><style id='iKbia'><dir id='iKbia'><q id='iKbia'></q></dir></style></legend>

                          1. <i id='iKbia'><tr id='iKbia'><dt id='iKbia'><q id='iKbia'><span id='iKbia'><b id='iKbia'><form id='iKbia'><ins id='iKbia'></ins><ul id='iKbia'></ul><sub id='iKbia'></sub></form><legend id='iKbia'></legend><bdo id='iKbia'><pre id='iKbia'><center id='iKbia'></center></pre></bdo></b><th id='iKbia'></th></span></q></dt></tr></i><div id='iKbia'><tfoot id='iKbia'></tfoot><dl id='iKbia'><fieldset id='iKbia'></fieldset></dl></div>