I'm building a Nuget package that acts as a logger for other applications. One of the features it needs to house different config properties (slack webhook urls, application name, and etc...) and the developer can edit these values within the app.config
or whatever is the config file.
One of the approaches I've used was creating transform files suggested by the documentation Microsoft provided here
However, when testing the nuget package on a console application with both .Net Framework and Core, the config files do not have the settings the transform files have from the nuget package. After some research, it turns out if the project uses PackageReference
it cannot make changes to the configuration file.
For projects using packages.config, NuGet supports the ability to make transformations to source code and configuration files at package install and uninstall times. Only Source code transformations are applied when a package is installed in a project using
PackageReference
.
The last solution I tried was from this SO question here from one of the comments. However, still not seeing the change.
Right now, I'm outputting a config file after the build to the application's root folder. Then, the nuget package pulls the config properties into a class which can be shared among the different loggers.
Here is the nuspec
file:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>POS_LoggingModule</id>
<version>1.0.13</version>
<authors>...</authors>
<owners>...</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Simple library to post logging to a Slack channel.</description>
<tags>Slack</tags>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Microsoft.Extensions.Configuration" version="2.1.1" exclude="Build,Analyzers" />
<dependency id="Newtonsoft.Json" version="11.0.2" exclude="Build,Analyzers" />
<dependency id="System.Diagnostics.EventLog" version="4.5.0" exclude="Build,Analyzers" />
</group>
</dependencies>
<contentFiles>
<files include="any/netstandard2.0/contentFiles/logging.config" buildAction="Content" />
</contentFiles>
</metadata>
<files>
<file src="bin\Debug\netstandard2.0\POS_LoggingModule.dll" target="lib\netstandard2.0\POS_LoggingModule.dll" />
<file src="contentFiles\logging.config" target="content\contentFiles\logging.config" />
<file src="contentFiles\logging.config" target="contentFiles\any\netstandard2.0\contentFiles\logging.config" />
</files>
</package>
The nuget package uses .Net Core 2.1, and.Net Framework 4.6.1. I've been advised by a senior dev to change it to .Net Standard.
Thanks, and I am looking forward to everyone's feedback!