GoalHaving all dlls from the main project in one package instead of one package per dll/library/cs project.Basically, need to package the content of the bin folder of the main project.The package should not
- have dependencies as all are packed.
- have any file content
- be generated upon build
The need here is not having to pack for execution but to reference/use the code with LinqPad.
Context
- Azure pipeline to build the package.
- CS standard/sdk projects: Platform is composed of a main project, multiple project references and package references.
IssueHow to achieve the goal as it's not obvious.
A Solution
- Added this bit into the main project csproj, under
<Project Sdk="MSBuild.SDK.SystemWeb">
ta
<!-- Packaging for LPs --><PropertyGroup><PackageId>NAME OF THE PACKAGE TO GENERATE</PackageId><Authors>THE AUTHOR</Authors><Company>THE COMPANY NAME</Company><GeneratePackageOnBuild>false</GeneratePackageOnBuild><NuspecProperties>version=$(PackageVersion)</NuspecProperties><SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking><IncludeContentInPack>false</IncludeContentInPack></PropertyGroup><PropertyGroup><TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetTheFiles</TargetsForTfmSpecificBuildOutput></PropertyGroup><Target DependsOnTargets="ResolveReferences" Name="GetTheFiles"><ItemGroup><BuildOutputInPackage Include="$(OutputPath)\*.dll"></BuildOutputInPackage></ItemGroup></Target>
- Az CI Pipeline
Task 1 - Use NuGet to restore the solution (.sln)
Task 2 - Use Powershell to set the build number with the variables declared on the CI
Write-Host "##vso[build.updatebuildnumber]$(AssemblyBuildNumber).$(AssemblyMajorVersion).$(AssemblyMinorVersion).$(AssemblyRevisionNumber)"
This is important as it will initializePackageVersion
in<NuspecProperties>version=$(PackageVersion)</NuspecProperties>
.PackageVersion
is a reserved property.Task 3 - Use Visual Studio build (VsBuild@1) to build and pack the main csproj
- task: VSBuild@1 displayName: 'Name of the Task' inputs: solution: PathToProj/MySite.csproj msbuildArgs: '/p:SkipInvalidConfigurations=true /t:pack /p:PackageVersion="$(Build.BuildNumber)" /p:BuildAuthorizer=$(Build.RequestedForEmail) /p:langversion=latest' platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)' maximumCpuCount: true
- Task 4 - Use .Net Core to push to Az Artifacts. Select the nuget push command.
ConclusionThis generates a nupkg with no dependencies, no file content, just the dlls.No need to specify anything to include all of the PackageReference or ProjectReference declared in the main project.This approach provides flexibility as any changes (as in dll/dependency renamed, added, removed, version upgraded) will be automatically packed.
Hope this help!
This is a solution to share how to pack a project's dlls (with project and package references).