Environment variables not being used when debugging through a Service Fabric project

前端 未结 3 1259
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 00:56

When creating an ASP.NET Core app an environment variable called ASPNETCORE_ENVIRONMENT=Development will be set for you and when debugging you will see that the

3条回答
  •  囚心锁ツ
    2021-01-13 01:17

    Reference for this answer: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-manage-multiple-environment-app-configuration

    I ran into the same issue with the default template. The following is similar to Duncan's answer but with two important differences: 1) You will not have to change any template code within the service, and 2) the IHostingEnvironment will be properly set.

    First, add the ASPNETCORE_ENVIRONMENT variable to the element of the PackageRoot\ServiceManifest.xml file of the application service:

    
      
        
          MyService.exe
          CodePackage
        
      
      
        
      
    
    

    As in Duncan's response, there are two changes you'll make to the ApplicationManifest.xml of your Service Fabric Application project. First, setup a parameter (variable) so that it can be modified when the ApplicationParameters files are substituted based on the way you deploy the project. Then, add an EnvironmentalOverrides section to your ServiceManifestImport element. The results of the two additions will look something like this:

    
      
      
    
    
    
      
      
        
      
    
    

    Finally, you can add in the proper values in the individual ApplicationParameters files:

    
      
      
    
    

    At this point, you can remove the variable from your service's Properties - Debug environmental variables.

提交回复
热议问题