deploy multi project - appsettings.json not found
SHackauf opened this issue · 7 comments
I changed my .Net google cloud function to a multi-project deployment. The function works on the server but I found out, that the appsetting.json is not more found from the framework.
My source folders look like the following
My analysis showed me, that the appsettings.json file is deployed on the server. The problem is, that the framework searches the appsettings.json file in the workspace (Environment.CurrentDirectory) folder and not in the folder of the main project where for example Visual Studio searches the file.
When I deploy the config file from the root folder and not from the main project folder then the framework finds the config file.
Would it be possible that the framework searches the config file in the root and in the main project folder? Then the deployment would be much easier because the cloud functions would run like Visual Studio.
Sure I can add the real position of the configuration file inside ConfigureAppConfiguration via configuration.AddJsonFile. But then my configuration file is behind the environment properties and I overwrite them.
When you say "the framework searches the appsettings.json file" could you clarify what you mean? There's nothing within the Functions Framework to do anything specific for settings... it just uses the regular ASP.NET Core configuration provider.
If you could provide a zip file with a minimal example for me to experiment with, I'll have a look. There's no guarantee that we'll be able to do anything without reinventing the wheel (I definitely don't want to write a new config provider) but I can experiment. It's unlikely to be before late next week though.
Thanks for the fast response. I created this morning a small example with the problem.
GoogleCloudFunction.zip
Inside the solution, you find three examples:
- 1 = Shows the problem
- 2 = Shows a workaround via deploy appsettings.json in the root folder
- 3 = Shows a workaround I made inside the StartUp. Unfortunately, with this workaround, I overwrite the environment properties.
In every example, you will find a script folder where my deploy command is included. Be careful with the run of the Powershell. You need to restart the Powershell UI when you change the example.
The examples based on a Http Cloud Function and all have the following URL listeners:
/check => Checks the appsetting.json property customerId
/file => Shows all files from the compiled application
/config => Shows all found configuration from IConfiguration and Environment.GetEnvironmentVariables
I hope this small example shows you the problem well enough.
Wonderful - thanks very much. That will be massively helpful. I'm really sorry that I won't be able to get to it today, but I promise I'll look as soon as I can.
Right, I've looked into this now, and I believe it's something that would need to be addressed in the buildpack. I've filed GoogleCloudPlatform/buildpacks#105 - if you could have a look and check that it looks appropriate to you, that would be really great.
I checked the created issue and for me, it looks very well described. It is clear, what the problem is.
Good news! It's now working :)
It turns out that you've already got the workaround in your project file:
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Ideally we'd like to make it so you don't need that, but it's not too bad a workaround for now.
I'll close this issue now as it looks fixed to me - if you could retest it yourself with your real code, that would be fabulous.
It's just possible that I'm using a different build pack version to you... if this doesn't work, please look in the build log that's listed in the deploy step output, and in step 1 ("detector") look for a line like this:
Status: Downloaded newer image for us.gcr.io/fn-img/buildpacks/dotnet3/builder:dotnet3_20210228_3_1_406_RC00
I believe that Docker tag for the dotnet3 builder is the important part.