nuget-packageslock2nix icon indicating copy to clipboard operation
nuget-packageslock2nix copied to clipboard

Fails to build "runtime" packages

Open gepbird opened this issue 1 year ago • 4 comments

I'm having trouble building a dotnet project that depends on DotNetEnv. This dependency depends on "normal" packages, for example NETStandard.Library, but it also depends on "runtime" packages, like runtime.any.System.Text.Encoding.

With your repo "normal" packages build fine, but "runtime" packages fail to build: error NU1101: Unable to find package runtime.any.System.Text.Encoding. No packages exist with this id in source(s): nugetSource.

Using the nixpkgs fetch-deps script works for "normal" and "runtime" packages too.

I made minimal reproducible flake:

# Build the failing nuget-packageslock2nix version
nix build github:gepbird/dotnet-lock-test#with-nuget-packageslock2nix

# Build the working deps.nix version
nix build github:gepbird/dotnet-lock-test#with-deps-nix

Any help would be appreciated, and thanks for your time and effort you put into this project :)

gepbird avatar Feb 15 '24 08:02 gepbird

I had a look to this issue (I'm starting with Nix so bear with me) and the packages.lock.json is missing the runtime dependencies. Ideally, this flake could handle it by itself by determining the current runtime but in the meantime, you can add the runtime explicitly to the csproj so runtime deps will be added to the packages.lock.json during dotnet restore :

  <PropertyGroup>
   ...
    <Nullable>enable</Nullable>
    <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>      <-------------------- (example here, put your real RID)
  </PropertyGroup>

and then nix build .#with-nuget-packageslock2nix should work properly

MrLuje avatar Sep 28 '24 21:09 MrLuje

I had a look to this issue (I'm starting with Nix so bear with me) and the packages.lock.json is missing the runtime dependencies. Ideally, this flake could handle it by itself by determining the current runtime but in the meantime, you can add the runtime explicitly to the csproj so runtime deps will be added to the packages.lock.json during dotnet restore :

  <PropertyGroup>
   ...
    <Nullable>enable</Nullable>
    <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>      <-------------------- (example here, put your real RID)
  </PropertyGroup>

and then nix build .#with-nuget-packageslock2nix should work properly

Thanks a lot @MrLuje, this solved the issue!

As an addition, multiple RIDs can be specified with the plural RuntimeIdentifiers, for example:

    <RuntimeIdentifiers>linux-x64;linux-arm64</RuntimeIdentifiers>

From the perspective of this flake, I think the most can we do is add a better warning message, I don't think we should alter the lockfile when building the package.

gepbird avatar Sep 29 '24 12:09 gepbird

I’ll try to take a look at improving this case, so I’m leaving this open as a TODO for me.

However, from the experience I had with .NET lock files I would recommend defining all the runtime identifiers you support in the csproj file as @gepbird suggests, cause otherwise contributors on different operating systems can run into problems with the lockfiles changing for no reasonable reason.

mdarocha avatar Jan 16 '25 11:01 mdarocha

Great to see you again after 2 years!

Defining runtime identifiers fixed this issue for me, but perhaps some better error message would be nice. For example somehow detecting the absence of runtime identifiers, and raising a warning/error.

FYI this flake is broken with the latest nixpkgs (tested this a few weeks ago, and I didn't see it getting fixed). I pinned nixpkgs to an older version in my project that uses nuget-packageslock2nix. See https://github.com/NixOS/nixpkgs/issues/347310

gepbird avatar Jan 16 '25 11:01 gepbird

@gepbird I've pushed some updates, from my testing, it should now work with newest nixpkgs-unstable.

mdarocha avatar May 27 '25 18:05 mdarocha

Dropping <RuntimeIdentifiers>linux-x64;linux-arm64</RuntimeIdentifiers> from my csproj still builds, thanks @mdarocha !

gepbird avatar May 27 '25 18:05 gepbird