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.
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>
Exception:
The configuration file 'appsettings.prod.json' was not found and is not optional. The physical path is '/azure-functions-host/appsettings.prod.json'.\n 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
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());
}
What this happens? Why just this file isn't published?
I've tried a lot of things like CopyToPublishDirectory = Always
option and other stuff.
I've searched for the appsettings.prod.json file inside of the image/host and I haven't found it.