I have created a nuget package where I am in need of adding a section to appsettings.json, or add my own configuration file that is copied into the application, but I am unable to figure out how.
I want this:
{
"mysection" :
{
"value1": "value,
"value2": "value"
}
}
to be added to the configuration file, or a file containing this to be copied when downloading the nuget package. We are using Visual Studio Team Services to build and host the nuget packages.
<ItemGroup>
<EmbeddedResource Include="settings.json" Pack="true">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
You want to edit nuspec file and use files element and add files there.
<files>
<file src="myConfig.json" target="Content" />
</files>
If you are using NuGet 3.3+ or PackageReference with NuGet 4+ you should use contentFiles elemenet instead.
<contentFiles>
<files include="any/any/myConfig.json" buildAction="None" copyToOutput="true" flatten="true" />
</contentFiles>
Documentation recommends to specify both elements to achieve maximum compatibility. You can read more here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With