0

I have a solution like that:

  • Package1
  • Package2

Both are Nuget packages, Package2 is referencing Package1 as a project reference. Now if I publish Package2 from what I understand this reference will get converted to Package1 Nuget (which I want), but what happens as well is that I do not have control over versioning it seems. So if I update Package1 to a new major version, that will lead to Package2 breaking.

Is there a way to control a version in this case?

This is what I have tried so far, but it is giving me some troubles during the build because of package.lock.json mismatch. (dotnet restore --locked-mode results in NU1004: The package references haver changed")

<ItemGroup>
    <PackageReference Include="Package1" Version="1.*" />    
</ItemGroup>
    
<ItemGroup>
  <ProjectReference Include="..\Package1\Package1.csproj" />
</ItemGroup>

It seems that the generated nuspec includes this:

<dependency id="Package1" version="<Package2Version>" exclude="Build,Analyzers" />

Which means if I always publish both packages together and they will be on the same version it will work, but it of course have some obvious downsides like publishing the packages with no changes e.g.

And what I want is to control <Package2Version>, ideally so that it would be set to version from Package1.csproj file instead of version from Package2.csproj file.

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
  • Where do you host your packages? Normally updating a nuget package itself doesn't break any projects as you are still able to use the older version. Usually you see the installed version and maybe another version bracketed, which indicates a reference. So either deploy nuget packages the usual way (to a registry) and provide different versions or also update both projects to fit the versions. I'm also remembering that there are options to define versions, but those are not working as intended (e.g. preventing nuget manager to show updates although you want to limit version to a specific one) – DanielD Jun 23 '23 at 14:18
  • I host in github packages, but that probably should not be any different I suppose. – Ilya Chernomordik Jun 23 '23 at 14:55
  • It seems a bit odd that you referenced it as project instead of building and publishing both packages seperately. Why don't you just use package1 as normal nuget package installation? – DanielD Jun 23 '23 at 18:55
  • I can do that of course, but then then if I want to make changes in both projects and test them together - I would have to publish the package first. This is what I want to avoid in the first place (why I have them in the same solution). – Ilya Chernomordik Jun 26 '23 at 07:54
  • Well you can still debug like that and test, simply include the built .dll files or reference the project itself if possible. You could also use them inside a test project and reference them directly to not having adding and deleting your references all the time. Just pack and publish them seperately afterwards to prevent messing around with the versions. – DanielD Jul 03 '23 at 10:37

0 Answers0