Closed RohitM-IN closed 5 months ago
Interesting! Did you just add an empty appsettings.json file, or did it contain anything? It looks as though it failed in the deployment pipeline while trying to get a particular value (though it's hard to tell what value). I'm going to move this issue over to Statiq Web since that's where the deployment pipeline lives and continue investigating.
Quick question - where are "NetlifySiteId" and "NetlifyAccessToken" defined? I see them being used to configure the Netlify deployment, but where are those values coming from? Were they defined anywhere before you added the appsettings.json file?
Ah, I see what's going on here. Basically, the DeployToNetlify()
extension method is intended to specify the actual value of the NetlifySiteId
and NetlifyAccessToken
settings (whether that's directly or via something like a delegate). However, to allow more complicated logic it does take a Config<string>
. Here's the code of that extension, which might make this a little clearer:
public static TBootstrapper DeployToNetlify<TBootstrapper>(
this TBootstrapper bootstrapper,
Config<string> siteId,
Config<string> accessToken)
where TBootstrapper : IBootstrapper =>
bootstrapper
.AddSettingsIfNonExisting(new Dictionary<string, object>
{
{ WebKeys.NetlifySiteId, siteId },
{ WebKeys.NetlifyAccessToken, accessToken }
});
See how it's just calling AddSettingsIfNonExisting()
? When those settings aren't defined elsewhere, the Program.cs
code above ends up adding them as Config.FromSetting<string>("NetlifySiteId")
, etc. So what's happening is that the Netlify deployment module looks for the setting NetlifySiteId
, finds it, and then evaluates the Config.FromSetting<string>("NetlifySiteId")
, which looks for the setting NetlifySiteId
, finds it, etc. on and on. By adding an appsettings.json
file with those values, the AddSettingsIfNonExisting()
sees that they're already defined and doesn't redefine them.
The "solution" here is to either specify the value of these settings directly in the Program.cs
file, or specify them elsewhere like an appsettings.json
file or an environment variable. In other words, you don't need to call DeployToNetlify()
in your Program.cs
at all if those settings are defined somewhere else - Statiq will find them and trigger the deployment if they're available. Think of the DeployToNetlify()
extension not as a "turn it on" switch but as a "configure it" helper if that makes sense.
I'll make a note in the documentation to clarify this for all the deployment pipelines, and I also made a small improvement to how this sort of recursive key expansion is reported so it's clearer. Here's what your scenario (without the appsettings.json
file) would output going forward:
I found this issue when deploying i forgot to add appsettings.json and this happened after adding the file it worked like a charm
program start
Steps to reproduce :
1) Dont Add appsettings.json 2) run deploy with args
deploy -s IgnoreInvalidXrefs=true