I want to run a local/internal NuGet repository. I think I've figured out how to "reuse" existing NuGet packages by including them in a dummy project using NuGet and scanning the package file to grab my locally-cached .nupkg
files, but...
.nupkg
) from a project, automatically including all dll
dependencies and not just those grabbed via NuGet?Specifically:
.dll
files/other projects <-- this is the missing part .nupkg
From what I've found, you're supposed to do things like
.csproj
file to add <BuildPackage>true</BuildPackage>
to include dependencies.nuspec
file and manually list your dependencies (similar ?)nuget pack
on your .nuspec
fileBut everything is manual, which is stupid. Even the semi-automatic solutions are still awkward or half-manual:
.nuspec
templates - doesn't seem to include dependencies, just metadatanuget pack via build-event (step #5), which you need to add manually to every project, and it has its own quirks:
"$(SolutionDir).nuget\NuGet.exe" pack "$(ProjectPath)" -Properties Configuration=Release move /Y *.nupkg "$(TargetDir)"
I'll settle for something that automatically creates a .nuspec
manifest from project references. Then theoretically that + the nuget build-event can be rolled up into a build-project/nuget package, which is what I really want to see.
As I remember in the past nuget manager did dependencies installation automatically. The package manager will show the dependencies even if they are not explicitly declared in nuspec (docs.microsoft.com/en-us/nuget/reference/…) - as they are added automaticalky.
Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.
Your point #3 (Add references to various .dll files/other projects <-- this is the missing part) really contains two different issues: (1) add references to various dll files, and (2) add references to other projects in the same solution.
Number (2) here has gotten some added support as of NuGet 2.5. You can add an option to include references to other projects in the same solution when creating a NuGet package for a project:
nuget pack projectfile.csproj -IncludeReferencedProjects
projectfile.csproj
references any other projects in your solution that also is exposed as NuGet packages, these projects' NuGet packages will be added as dependencies.As for (1), if you find yourself often adding dlls to your projects that aren't available as NuGet packages, you could just create your own (internal) NuGet packages with these files. If you then add these dlls as a NuGet package instead of the files directly, this NuGet package will be a dependency in your project's NuGet package.
I found a well-written article on this topic. I have the same issue with certain packages that have a hierarchy of dependencies and up until now I've been uploading each as a separate NuGet package (what. a. waste. of. time)
I've just tested the solution found here: https://dev.to/wabbbit/include-both-nuget-package-references-and-project-reference-dll-using-dotnet-pack-2d8p
And after examining the NuGet package using NuGet Package Explorer, the DLLs produced by referenced projects are indeed present. I'm going to test by actually submitting this package to NuGet and testing it.
Here's my source in case it is helpful to you: https://github.com/jchristn/NuGetPackTest
And the test NuGet package: https://www.nuget.org/packages/NuGetPackTest/1.0.0
The solution appears to work well. I don't know what it's going to look like when there are layers of references, I'm sure it could get really hairy and really fast.
.csproj from NuGetPackTest library which references project TestLibrary (portions removed for brevity)
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1;net461</TargetFrameworks> ... <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <!-- added this line --> <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput> </PropertyGroup> <ItemGroup> <!-- modified this ProjectReference to include the children ReferenceOutputAssembly and IncludeAssets --> <ProjectReference Include="..\TestLibrary\TestLibrary.csproj"> <ReferenceOutputAssembly>true</ReferenceOutputAssembly> <IncludeAssets>TestLibrary.dll</IncludeAssets> </ProjectReference> </ItemGroup> <!-- added this section --> <Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage"> <ItemGroup> <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/> </ItemGroup> </Target> </Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With