I have a simple .NET Core 3.1 class library that implements some logging functionality inside classes and has a nlog.config
file. The .csproj
looks like this
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NuspecFile>Sima.Logging.nuspec</NuspecFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.7.12" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
</ItemGroup>
</Project>
As you can see, my .csproj
references a .nuspec
file. I need to do this because I want to include the nlog.config
as a content file. The .nuspec
looks like this
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Sima.Logging</id>
<version>1.0.0</version>
<contentFiles>
<files include="**/nlog.config" buildAction="Content" copyToOutput="true" flatten="true" />
</contentFiles>
<dependencies>
<group>
<dependency id="NLog" version="4.7.12" exclude="Build,Analyzers" />
<dependency id="NLog.Web.AspNetCore" version="4.9.3" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
<files>
<file src="contentFiles\**" target="contentFiles" />
</files>
</package>
After packaging my library using dotnet pack
, the nupkg only includes the two dependencies to NLog, but none of my actual code (in my class) is included in the package.
It seems like NuGet doesnt know what to actually build. What did I miss?
CodePudding user response:
When creating Nuget package (*.nupkg), you must define all files you want to be included in that package. In nuspec config you are missing following:
<files>
<file src="bin\Debug\*.dll" target="lib" />
</files>
Where bin\Debug\
is the output path of your build. For further reference please visit the documentation.