ASP.NET Core Environment variables not being used when debugging through a Service Fabric project -
when creating asp.net core app environment variable called aspnetcore_environment=development
set , when debugging see ihostingenvironment
set development
.
the problem when use same project in solution set service fabric environment variables don't seem injected , ihostingenvironment
returns "production".
how can resolve this?
note: i've set breakpoint in startup class observe ihostingenvironment variable.
reference answer: https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-manage-multiple-environment-app-configuration
i ran same issue default template. following similar duncan's answer 2 important differences: 1) not have change template code within service, , 2) ihostingenvironment
set.
first, add aspnetcore_environment
variable <codepackage>
element of packageroot\servicemanifest.xml
file of application service:
<codepackage name="code" version="1.0.0"> <entrypoint> <exehost> <program>myservice.exe</program> <workingfolder>codepackage</workingfolder> </exehost> </entrypoint> <environmentvariables> <environmentvariable name="aspnetcore_environment" value=""/> </environmentvariables> </codepackage>
as in duncan's response, there 2 changes you'll make applicationmanifest.xml
of service fabric application project. first, setup parameter (variable) can modified when applicationparameters
files substituted based on way deploy project. then, add environmentaloverrides
section servicemanifestimport
element. results of 2 additions this:
<parameters> <parameter name="myservice_instancecount" defaultvalue="-1" /> <parameter name="aspnetcoreenvironment" defaultvalue="" /> </parameters> <servicemanifestimport> <servicemanifestref servicemanifestname="myservicepkg" servicemanifestversion="1.0.0" /> <environmentoverrides codepackageref="code"> <environmentvariable name="aspnetcore_environment" value="[aspnetcoreenvironment]" /> </environmentoverrides> </servicemanifestimport>
finally, can add in proper values in individual applicationparameters
files:
<parameters> <parameter name="myservice_instancecount" value="-1" /> <parameter name="aspnetcoreenvironment" value="development" /> </parameters>
at point, can remove variable service's properties - debug environmental variables.
Comments
Post a Comment