1

I am creating a NuGet package which contains a .Net Standard DLL and a config file. This project is supposed to support both .Net Core and .Net Framework.

In a few words, packing this DLL and config file using dotnet pack and a .nuspec file, creates a package that is not "fully compatible" with .Net Core:

enter image description here

More details here:

In the project .csproj I am adding a .nuspec file reference:

<NuspecFile>.\MyProject.nuspec</NuspecFile>

Next to which I have the following .nuspec file:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>MyProject</id>
        <version>1.0.0</version>
        <authors> </authors>
        <description>some text</description>
    </metadata>
    <files>
        <file src="MyProject.targets" target="Build\"/>
        <file src="NLog.config" target="Build\" />
        <file src="bin/Release/MyProject.dll" target="lib\dotnet"/>
    </files>
    <dependencies>
        <dependency id="newtonsoft.json" version="11.0.2" />
        <dependency id="nlog" version="4.5.10" />
    </dependencies>
</package>

Then next to these two, I am having a .targets file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="NLog.config">
      <Link>NLog.config</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

I am packing this into a nuget package using dotnet pack command within VSTS, giving it the path to my .csproj file.

I am trying to do this complicated approach because I want that NLog.config to be included automatically into the projects installing this package and also setting this config file property Copy to Output Directory to Copy always, approach which is taken from here and here, but which does not work yet.

As a side note, I say the same behavior before when I tried dotnet pack and giving it the path to the .nuspec file, but it went away when I changed the path to the .csproj.

Has anyone any idea why this warning appears in the .Net Core clients using this package when packing it with .nuspec file?

Thank you so much for your patience and help!

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76
  • Things should go in a \lib\NetStandard16 (or similar) folder. as defined in your nuspec you're only putting things for netcore. Visual studio falls back and gives you that warning as a stop-gap until everyone is updated – pinkfloydx33 Sep 26 '18 at 19:15
  • 1) out of curiosity, why are you using a nuspec file instead of the [NuGet metadata properties](https://learn.microsoft.com/en-us/dotnet/core/tools/csproj#nuget-metadata-properties) in the csproj file? 2) files won't be installed by NuGet automatically for .NET Core (as far as I'm aware). My understanding is support for that had been dropped by NuGet with .NET core – willwolfram18 Sep 27 '18 at 04:52
  • @willwolfram18 I have used NuGet metadata properties and this warning was gone, everything was working good, and the NLog.config file was installed properly in the client projects, with the only exception that it was not set to `Copy always` to the output directory. – meJustAndrew Sep 27 '18 at 06:11
  • @pinkfloydx33 since I read [this topic here](https://stackoverflow.com/questions/34611919/how-to-package-a-portable-net-library-targeting-net-core) I tried to follow the same structure it suggested, but with no results. I am putting only things for **.Net Standard** so they could be installed on .Net Core and .Net Framework clients. – meJustAndrew Sep 27 '18 at 06:13

1 Answers1

1

According to https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks and https://learn.microsoft.com/en-us/nuget/reference/target-frameworks#supported-frameworks the folder structure in the nuget package should probably be \lib\netstandard1.6 or \lib\netstandard2.0 or whatever version you compiled against (as pinkfloydx33 already tried to point out). \lib\dotnet is deprecated (https://learn.microsoft.com/en-us/nuget/reference/target-frameworks#deprecated-frameworks) and I don't know if support for it has been removed already or not.
I have not tested this, so this is something you could try, if you did not solve it meanwhile.

Another way to make progress would be to inspect and compare the actual resulting packages (with nuspec and without).

uebe
  • 488
  • 4
  • 11