I've a dotnet solution which consists of many .NET Framework 4.8 class library projects. Some projects have other packages installed, like log4net, Oracle.ManagedDataAccess, GraphQL.Client. In this solution file, I've a base NET Framework 4.8 class library project to which I've added all the other class libraries as dependencies.
Now I use azurepipelines.yml to build the whole solution and pack the base project and push it as nuget package. Now my nuget package has all the dlls plus it has dlls of log4net and other nuget packages that I installed to my projects. So the size of this package is very big. Instead of that, I want only my project dlls along with Microsoft dlls, and not the third party packages in my nuget package. And when I install this nuget package in my other solutions, I want the other libraries (log4net, Oracle.ManagedDataAccess, GraphQL.Client) to be installed along with that - to the "packages" folder.
This will help me to have a small nuget package and these extra library dlls will be installed separately. How can I do this?
- task: DotNetCoreCLI@2
displayName: 'Dotnet Pack'
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: '**/MyBaseProject.csproj'
versioningScheme: 'off'
includeReferencedProjects: true
- task: NuGetCommand@2
displayName: 'NuGet Push'
inputs:
command: 'push'
feedsToUse: 'select'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/XX*.nupkg'
versioningScheme: 'off'
allowPackageConflicts: true
publishVstsFeed: 'feedIDHere'
My csproj is like below
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<PackageId>MyPackage</PackageId>
<Version>1.1.10</Version>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Business\xx1.csproj">
<ExcludeAssets>all</ExcludeAssets>
</ProjectReference></ProjectReference>
<ProjectReference Include="..\Logging\xx2.csproj">
<ExcludeAssets>all</ExcludeAssets>
</ProjectReference></ProjectReference>
<ProjectReference Include="..\Services\xx3.csproj">
<ExcludeAssets>all</ExcludeAssets>
</ProjectReference></ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\Business\bin\$(Configuration)\*.dll">
<PackagePath>lib\net48</PackagePath>
<Pack>true</Pack>
<Visible>false</Visible>
</None>
</ItemGroup>
</Project>
I rectified the issue by adding a nuspec file & changing the dotnet pack job to look for nuspec.
- task: DotNetCoreCLI@2
displayName: 'Dotnet Pack'
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: '**/Myprjoect.nuspec'
versioningScheme: 'off'
nobuild: true
includeReferencedProjects: true
The nuspec file is like below.
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>Package Name</id>
<version>1.1.15</version>
<dependencies>
<group targetFramework=".NETFramework4.8">
<dependency id="GraphQL.Client" version="3.2.0" />
<dependency id="iTextSharp" version="5.5.9" />
<dependency id="log4net" version="2.0.5" />
<dependency id="Oracle.ManagedDataAccess" version="19.11.0" />
</group>
</dependencies>
</metadata>
<files>
<file src="**\*.dll" exclude="**\GraphQL.*;**\Oracle*.dll;**\obj\**\*.*;**\itextsharp.dll;**\log4net.dll" target="lib\net48" />
</files>
</package>
These changes helped me to decrease my nuget package size from >10MB to <4MB. And when I install my package in other solutions via Nuget Package Manager in Visual Studio, the dependecies get installed separately.