Nuget packing not including dependncies in right way

0

I have a C# library, let say "Utilities" that uses Log4net as dependency, I am using .net framwork 4.6.1, I finished developeing this library and do a nuget pack Utilities.projcs and then push this package.

While I'm try to use this Utilities in another project that which is an asp.net core "2.1" project, I got this exception

**Method not found: 'log4net.ILog log4net.LogManager.GetLogger(System.String)'.**
System.MissingMethodException
      HResult=0x80131513
      Message=Method not found: 'log4net.ILog log4net.LogManager.GetLogger(System.String)'.
      Source=Utilities
      StackTrace:
       at Utilities.Logging.MyLogManager.GetLogger(String loggerKey)

My Utilities nuget spec file

<?xml version="1.0"?>
<package >
  <metadata>
    <id>Utilities</id>
    <version>1.2.0</version>
    <title>Internal Utilities</title>
    <authors>My Team</authors>
    <owners>My Team</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>This dll contains parsers,loggers and other functionalities that is commonly used.</description>
    <releaseNotes>Rlease notes</releaseNotes>
    <copyright>Copyright 2020</copyright>
    <tags>Utilities</tags>
    <dependencies>
      <dependency id="log4net" version="2.0.8" include="all"/>
    </dependencies>
  </metadata>
  <files>
    <file src="bin\Debug\log4net.dll" target="" />
    <file src="bin\Debug\log4net.xml" target="" />
    <file src="bin\Debug\Utilities.dll" target="" />
  </files>
</package>

Any ideas to solve this, I spent the last couple of days to solve it but no luck

NOTE: When I add Reference manually by location in my pc (My library + Log4net) it works fine!!

asp.net-core
nuget
nuget-package
.net-4.6.1
nuget-spec
asked on Stack Overflow Apr 15, 2020 by Mostafa Hassan • edited Apr 15, 2020 by Mostafa Hassan

1 Answer

1

Create class library in .net standard.
For more info about .net standard visit https://docs.microsoft.com/en-us/dotnet/standard/net-standard

How to create .net standard class library -> https://docs.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?tabs=csharp

How to create .net standard Nuget -> https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio?tabs=netcore-cli

.net infra
this image will help you understand the concept behind shared libraries.

answered on Stack Overflow Apr 15, 2020 by Manish

User contributions licensed under CC BY-SA 3.0