I have a Dotnet Core 2.1 project which has both a nuspec and a csproj file - one major hassle is that the csproj describes dependencies like this:
<ItemGroup>
<PackageReference Include="Refit" Version="4.6.16" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1" />
<PackageReference Include="Refit.HttpClientFactory" Version="4.6.16" />
</ItemGroup>
While the nuspec does this:
<dependencies>
<dependency id="Refit" version="4.6.16" />
<dependency id="Refit.HttpClientFactory" version="4.6.16" />
<dependency id="Microsoft.AspNetCore.All" version="2.1" />
</dependencies>
Both are easily out of sync and keeping the same information twice is annoying. Is there a way to avoid that?
There is certain to be a easy way for this, just use dotnet pack
instead of nuget pack
and .csproj
files instead of .nuspec
files.
dotnet pack
supports 2 ways to specify the nuget package properties.
.nuspec
file, which would disable the 2nd way.csproj
file
dotnet pack
supports both ways but you must add a NuspecFile
property to reference the .nuspec
file and there are a lot of bugs and feature missings for the legacy way, which means you can only use the new one.
dotnet pack
executes restore and build on the project and packs it with a automatically generated .nuspec file resolving all nuget metadata properties in .csproj
as .nuspec
properties and all projects references as nuget package references (This is not available with manually specified .nuspec
file), so that versioning, dependency, and package file structure things can be automatically ensured.
My own library could be an example. Version and dependency things are specified for only once at where they are supposed to be and there are no longer any annoying duplicate configurations. Executing dotnet pack
on the solution directory would generate all good .nupkg
s on the dist
directory.
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