0

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!

DanStockham
  • 31
  • 1
  • 4
  • Hi there! Your question is too broad. Here, on stackoverflow, we dealing with coding issues, so if you have a problem with your code (exceptions, unpredictable behavior, etc.) - edit your question or ask another one. You may also find this link useful: https://stackoverflow.com/help/how-to-ask – jazb Nov 05 '18 at 05:56
  • Since you are using .NET Core, why not integrate with their Microsoft.Extensions.Configuration stack? App.config usage is possible again in recent versions but not really used. .NET Standard libraries for example can't rely on the target platform even supporting app.config – Martin Ullrich Nov 05 '18 at 07:07
  • @johnB Could you elaborate more as to why the question is too broad? – DanStockham Nov 05 '18 at 14:43

0 Answers0