Reputation: 70
I'm writing an API, with some assemblies, I'd those assemblies to be published as nuget packages (it's actually done).
It's splitted over :
I'd like to release each one of those on nuget, but some are dependant to some others (example Game is dependant to Core, Data, Enums and Packets, Data is dependant to Enums...)
Should I link them with local reference or should I link each of their links to respective "remote packages" ? Here is the link of the related API : https://github.com/BlowaXD/ChickenAPI/
Upvotes: 2
Views: 321
Reputation: 1504182
You don't need to use a nuspec file to do this - regular .NET Core SDK project files work fine.
Use <ProjectReference>
to refer to one project from another, and that will be part of the dependencies in the NuGet package.
For example:
ChickenApi.Core.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- TODO: Extra NuGet properties, e.g. Description, Authors -->
<Version>1.0</Version>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
ChickenApi.Game.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- TODO: Extra NuGet properties, e.g. Description, Authors -->
<Version>1.0</Version>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ChickenApi.Core\ChickenApi.Core.csproj" />
</ItemGroup>
</Project>
If you run dotnet pack -c Release
on the solution, that will create two nupkg
files, one for each project. Just publish both packages, and all will be well.
One thing to be aware of though is that if you change ChickenApi.Core
and then depend on those changes in ChickenApi.Game
, you must publish both packages (with updated version numbers). It's easy to forget to change the version of ChickenApi.Core
, and publish a new version of ChickenApi.Game
which claims it's still referring to 1.0, but depends on changes that aren't in the published 1.0.
Upvotes: 3
Reputation: 70
I've succeed to do it through Nuget's .nuspec files.
Here is the XML i'm using to build it
<?xml version="1.0" encoding="utf-16"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>ChickenAPI.Game.Extensions</id>
<version>$(VERSION_OF_CHICKEN_API)</version>
<authors>BlowaXD</authors>
<projectUrl>http://github.com/BlowaXD/ChickenAPI</projectUrl>
<iconUrl>https://raw.githubusercontent.com/BlowaXD/ChickenAPI/develop/docs/_media/logo_256.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ChickenAPI.Game.Extensions is an collection of useful methods to manage game objects</description>
<summary>ChickenAPI is an API for Nostale Private Servers</summary>
<copyright>Copyright © BlowaXD 2019</copyright>
<language>en-US</language>
<dependencies>
<dependency id="ChickenAPI.Game" version="$(VERSION_OF_CHICKEN_API)" />
</dependencies>
</metadata>
</package>
and here the command line I'm using to build the package :
dotnet pack -c Release src/ChickenAPI.Core --output nupkgs /p:NuspecFile=chickenapi.core.nuspec /p:NuspecBasePath=.
Thanks to that declaring nuget packages that depend on each other in one solution other question.
This pull request will show how I solved the issue (with every single details) : https://github.com/BlowaXD/ChickenAPI/pull/96
Upvotes: 0