NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.81k stars 13.91k forks source link

Specifying `projectFile` as a path rather than string for `buildDotnetModule` causes duplicate assembly attributes error on build #301735

Open zlepper opened 6 months ago

zlepper commented 6 months ago

Describe the bug

If you specify the projectFile attribute using a path rather than a string for buildDotnetModule then you get a build failure due to duplicate assembly attributes.

Working:

{ buildDotnetModule, dotnetCorePackages }:

buildDotnetModule rec {
  pname = "my-web-api";
  version = "0.1";

  src=./.;
  projectFile = "./my-web-api.csproj";
  nugetDeps = ./deps.nix;

  dotnet-sdk = dotnetCorePackages.sdk_8_0;
  dotnet-runtime = dotnetCorePackages.aspnetcore_8_0;
}

Not working:

{ buildDotnetModule, dotnetCorePackages }:

buildDotnetModule rec {
  pname = "my-web-api";
  version = "0.1";

  src=./.;
  projectFile = ./my-web-api.csproj;
  nugetDeps = ./deps.nix;

  dotnet-sdk = dotnetCorePackages.sdk_8_0;
  dotnet-runtime = dotnetCorePackages.aspnetcore_8_0;
}

default.nix file:

{ pkgs ? import <nixpkgs> {}
, pkgsLinux ? import <nixpkgs> { system = "x86_64-linux"; }
}:

{
  my-web-api = import ./my-web-api.nix { inherit (pkgs) buildDotnetModule  dotnetCorePackages; };
}

As a side note: I'm not sure it should even work with a path, but my naive expectations says it should, so those might be in the wrong here instead :)

Steps To Reproduce

  1. Create a new webapi dotnet project: dotnet new webapi --name my-web-api
  2. Fetch nuget deps: nix-build -A my-web-api.fetch-deps and ./result
  3. Build project: nix-build -A my-web-api

Expected behavior

It builds in both cases

Additional context

Logs from failure:

this derivation will be built:
  /nix/store/q97jncl6xh5cjmk33jqlvv73m1f49c85-my-web-api-0.1.drv
building '/nix/store/q97jncl6xh5cjmk33jqlvv73m1f49c85-my-web-api-0.1.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/fb30sjgd1mw8gqrl881v14wz7ccvcb64-my-web-api
source root is my-web-api
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
Executing dotnetConfigureHook
Cannot find a manifest file.
For a list of locations searched, specify the "-d" option before the tool name.
No tools were restored.
  Determining projects to restore...
  Restored /nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj (in 1.78 sec).
Fixing up native binaries...
Found binary: /build/tmp.l5mtaKszvH/.nuget/packages/microsoft.netcore.app.runtime.linux-x64/8.0.1/runtimes/linux-x64/native/createdump, fixing it up...
Finished dotnetConfigureHook
Running phase: buildPhase
Executing dotnetBuildHook
MSBuild version 17.8.3+195e7f5a3 for .NET
/nix/store/obj/Release/net8.0/linux-x64/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(13,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]

Build FAILED.

/nix/store/obj/Release/net8.0/linux-x64/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(13,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
/nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
    0 Warning(s)
    8 Error(s)

Time Elapsed 00:00:02.82
error: builder for '/nix/store/q97jncl6xh5cjmk33jqlvv73m1f49c85-my-web-api-0.1.drv' failed with exit code 1;
       last 10 log lines:
       > /nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
       > /nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
       > /nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
       > /nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
       > /nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
       > /nix/store/obj/Release/net8.0/linux-x64/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [/nix/store/2f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj]
       >     0 Warning(s)
       >     8 Error(s)
       >
       > Time Elapsed 00:00:02.82
       For full logs, run 'nix-store -l /nix/store/q97jncl6xh5cjmk33jqlvv73m1f49c85-my-web-api-0.1.drv'.

Notify maintainers

@corngood @mdarocha

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

zlepper@nixos ~/p/my-web-api> nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.82, NixOS, 23.11 (Tapir), 23.11.5742.219951b495fc`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

corngood commented 6 months ago

I don't think we can realistically make this work. It's going to try to build /nix/store/f1dl7hsx0c5hqwfhnps2i9yw2kgr5z8-my-web-api.csproj, which is no longer in it's source-tree, so it won't be able to find source files, nuget.config, global.json, etc.

projectFile really needs to be a relative path to something inside src. Perhaps we could a check for this?

zlepper commented 6 months ago

That's entirely fair, I do try to create reports to also help other people encountering the issue in the future, so maybe they can get unstuck :)

mdarocha commented 6 months ago

Adding a check and giving a meaningful error would be the best approach here. It'd improve UX without having to do any drastic changes