Packaging a Dotnet project

Hi!
I’m currently learning F#, and i want use Emacs with LSP Support. I’m definitely not confident with M$ stuff and don’t understand how the things work, but i want to the LSP backend, FSAC

I tried to follow the Wiki entry but got errors about XML Namespace, that i fix using the workaround provided by the wiki. But now i faced this error about a NOT compatible installed .NET SDK…

The derivation:

{ pkgs ? import <nixpkgs> {} }:
with pkgs;
buildDotnetPackage rec {
    pname = "fsac";
    baseName = pname;
    version = "0.50.0";
    src = ./.;

    projectFile = "FsAutoComplete.sln";
    buildInputs = [
    msbuild
    ];
    buildPhase = ''
    runHook preBuild
    msbuild /p:Configuration=Release ${projectFile}
    runHook postBuild
  '';
}

And complete backtrace

this derivation will be built:
  /nix/store/6lbvxq6svbfpipn7d0a724imnpzij4hl-fsac-0.50.0.drv
building '/nix/store/6lbvxq6svbfpipn7d0a724imnpzij4hl-fsac-0.50.0.drv'...
unpacking sources
unpacking source archive /nix/store/hijjl7zm3yr155myamcxmydgm5dv49qa-FsAutoComplete
source root is FsAutoComplete
patching sources
configuring
Placating Nuget in nuget.targets
Just to be sure, replacing Nuget executables by empty files.
Placating Paket in paket.targets
./.paket/paket.targets
Just to be sure, replacing Paket executables by empty files.
Patching F# targets in fsproj files...
./src/FsAutoComplete.BackgroundServices/FsAutoComplete.BackgroundServices.fsproj
./src/FsAutoComplete/FsAutoComplete.fsproj
./src/FsAutoComplete.Core/FsAutoComplete.Core.fsproj
./src/FsAutoComplete.Logging/FsAutoComplete.Logging.fsproj
./test/OptionAnalyzer/OptionAnalyzer.fsproj
./test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/DocumentSymbolTest/DocumentSymbolTest.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/FsdnTest/BasicTest.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/FoldingTests/FoldingTests.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/AutocompleteTest/AutocompleteTest.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/RenameTest/RenameTest.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/GoToTests/GoToTests.fsproj
./test/FsAutoComplete.Tests.Lsp/FsAutoComplete.Tests.Lsp.fsproj
building
Microsoft (R) Build Engine version 16.10.1 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 03/02/2022 14:12:27.
Project "/build/FsAutoComplete/FsAutoComplete.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Release|Any CPU".
A compatible installed .NET SDK for global.json version [6.0.100] from [/build/FsAutoComplete/global.json] was not found.
Install the [6.0.100] .NET SDK or update [/build/FsAutoComplete/global.json] with an installed .NET SDK:
  It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
  https://aka.ms/dotnet-download
A compatible installed .NET SDK for global.json version [6.0.100] from [/build/FsAutoComplete/global.json] was not found.
Install the [6.0.100] .NET SDK or update [/build/FsAutoComplete/global.json] with an installed .NET SDK:
  It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
  https://aka.ms/dotnet-download
Project "/build/FsAutoComplete/FsAutoComplete.sln" (1) is building "/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj" (2) on node 1 (default targets).
/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj(51,49): error MSB4057: The target "ResolveReferences" does not exist in the project.
Done Building Project "/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj" (default targets) -- FAILED.
Project "/build/FsAutoComplete/FsAutoComplete.sln" (1) is building "/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (8) on node 1 (default targets).
/nix/store/zxcn56jpdpg0785h4lj4jclbfckbd1zi-msbuild-16.10.1+xamarinxplat.2021.05.26.14.00/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(103,5): error MSB4181: The "Telemetry" task returned false but did not log an error. [/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj]
Done Building Project "/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (default targets) -- FAILED.
Done Building Project "/build/FsAutoComplete/FsAutoComplete.sln" (default targets) -- FAILED.

Build FAILED.

"/build/FsAutoComplete/FsAutoComplete.sln" (default target) (1) ->
"/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj" (default target) (2) ->
  /build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj(51,49): error MSB4057: The target "ResolveReferences" does not exist in the project.


"/build/FsAutoComplete/FsAutoComplete.sln" (default target) (1) ->
"/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (default target) (8) ->
(_CollectTargetFrameworkForTelemetry target) ->
  /nix/store/zxcn56jpdpg0785h4lj4jclbfckbd1zi-msbuild-16.10.1+xamarinxplat.2021.05.26.14.00/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(103,5): error MSB4181: The "Telemetry" task returned false but did not log an error. [/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj]

    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:00.75
error: builder for '/nix/store/6lbvxq6svbfpipn7d0a724imnpzij4hl-fsac-0.50.0.drv' failed with exit code 1;
       last 10 log lines:
       >
       > "/build/FsAutoComplete/FsAutoComplete.sln" (default target) (1) ->
       > "/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (default target) (8) ->
       > (_CollectTargetFrameworkForTelemetry target) ->
       >   /nix/store/zxcn56jpdpg0785h4lj4jclbfckbd1zi-msbuild-16.10.1+xamarinxplat.2021.05.26.14.00/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(103,5): error MSB4181: The "Telemetry" task returned false but did not log an error. [/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj]
       >
       >     0 Warning(s)
       >     2 Error(s)
       >
       > Time Elapsed 00:00:00.75
       For full logs, run 'nix log /nix/store/6lbvxq6svbfpipn7d0a724imnpzij4hl-fsac-0.50.0.drv'.

Thanks to all in advance :smiley:

This is because nixpkgs’s msbuild is version 16.10.1 (see https://github.com/NixOS/nixpkgs/commit/3672c0a33fe52d2dd9b383f9d4114ad2e62eb590) which contains .NET SDK version 5.0.301 (https://github.com/dotnet/msbuild/releases/tag/v16.10.1). The global.json file in the repo, by contrast, requires 6.0.100 or later.

Quick “fix” which probably won’t work: downgrade the global.json to specify 5.0.301. Lengthier actual fix is to upgrade the msbuild package in nixpkgs. Alternatively you could ditch buildDotnetPackage completely and just install dotnet-sdk_6 in a dev shell, and dotnet build from the command line.

1 Like

(By the way, I am a professional F# dev, and I consider Jetbrains Rider to be second to none as an F# IDE. It’s in nixpkgs.)

I would not be surprised to find that the build fails even with the right msbuild. FsAutoComplete uses the FAKE build system rather than msbuild directly. You might be able to build successfully, but it’s by no means guaranteed. Instead of running msbuild, you’ll need to follow the build instructions in the README, using dotnet fake build etc. (Note that FAKE doesn’t work on Apple Silicon, so if you’re on darwin-aarch64 you’re completely out of luck unless either msbuild happens to work out of the box, or you do a lot of work to move the repo away from FAKE.)

I’ve tried patching global.json but got basically the same errors… Building following the readme using a nix-shell seems to work.
Unfortunately it’s definitely not “reproducibile” or declarative enough…

I’m surprised you got “basically the same errors”. What did you do precisely?

sorry for the delay…

here’s the errors:

this derivation will be built:
  /nix/store/75vwvv1k2kx4ram7bcgshc4h2rkvs1jm-fsac-0.50.0.drv
building '/nix/store/75vwvv1k2kx4ram7bcgshc4h2rkvs1jm-fsac-0.50.0.drv'...
unpacking sources
unpacking source archive /nix/store/axmghzq77mlzsy5v12cmkgm9zxakh5r3-FsAutoComplete
source root is FsAutoComplete
patching sources
configuring
Placating Nuget in nuget.targets
Just to be sure, replacing Nuget executables by empty files.
Placating Paket in paket.targets
./.paket/paket.targets
Just to be sure, replacing Paket executables by empty files.
Patching F# targets in fsproj files...
./test/OptionAnalyzer/OptionAnalyzer.fsproj
./test/FsAutoComplete.Tests.Lsp/FsAutoComplete.Tests.Lsp.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/RenameTest/RenameTest.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/DocumentSymbolTest/DocumentSymbolTest.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/GoToTests/GoToTests.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/FoldingTests/FoldingTests.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/AutocompleteTest/AutocompleteTest.fsproj
./test/FsAutoComplete.Tests.Lsp/TestCases/FsdnTest/BasicTest.fsproj
./test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj
./src/FsAutoComplete.BackgroundServices/FsAutoComplete.BackgroundServices.fsproj
./src/FsAutoComplete/FsAutoComplete.fsproj
./src/FsAutoComplete.Logging/FsAutoComplete.Logging.fsproj
./src/FsAutoComplete.Core/FsAutoComplete.Core.fsproj
building
Microsoft (R) Build Engine version 16.10.1 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 03/08/2022 17:39:37.
Project "/build/FsAutoComplete/FsAutoComplete.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Release|Any CPU".
A compatible installed .NET SDK for global.json version [5.0.301] from [/build/FsAutoComplete/global.json] was not found.
Install the [5.0.301] .NET SDK or update [/build/FsAutoComplete/global.json] with an installed .NET SDK:
  It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
  https://aka.ms/dotnet-download
A compatible installed .NET SDK for global.json version [5.0.301] from [/build/FsAutoComplete/global.json] was not found.
Install the [5.0.301] .NET SDK or update [/build/FsAutoComplete/global.json] with an installed .NET SDK:
  It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
  https://aka.ms/dotnet-download
Project "/build/FsAutoComplete/FsAutoComplete.sln" (1) is building "/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj" (2) on node 1 (default targets).
/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj(51,49): error MSB4057: The target "ResolveReferences" does not exist in the project.
Done Building Project "/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj" (default targets) -- FAILED.
Project "/build/FsAutoComplete/FsAutoComplete.sln" (1) is building "/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (8) on node 1 (default targets).
/nix/store/zxcn56jpdpg0785h4lj4jclbfckbd1zi-msbuild-16.10.1+xamarinxplat.2021.05.26.14.00/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(103,5): error MSB4181: The "Telemetry" task returned false but did not log an error. [/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj]
Done Building Project "/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (default targets) -- FAILED.
Done Building Project "/build/FsAutoComplete/FsAutoComplete.sln" (default targets) -- FAILED.

Build FAILED.

"/build/FsAutoComplete/FsAutoComplete.sln" (default target) (1) ->
"/build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj" (default target) (2) ->
  /build/FsAutoComplete/src/FsAutoComplete/FsAutoComplete.fsproj(51,49): error MSB4057: The target "ResolveReferences" does not exist in the project.


"/build/FsAutoComplete/FsAutoComplete.sln" (default target) (1) ->
"/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (default target) (8) ->
(_CollectTargetFrameworkForTelemetry target) ->
  /nix/store/zxcn56jpdpg0785h4lj4jclbfckbd1zi-msbuild-16.10.1+xamarinxplat.2021.05.26.14.00/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(103,5): error MSB4181: The "Telemetry" task returned false but did not log an error. [/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj]

    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:00.74
error: builder for '/nix/store/75vwvv1k2kx4ram7bcgshc4h2rkvs1jm-fsac-0.50.0.drv' failed with exit code 1;
       last 10 log lines:
       >
       > "/build/FsAutoComplete/FsAutoComplete.sln" (default target) (1) ->
       > "/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj" (default target) (8) ->
       > (_CollectTargetFrameworkForTelemetry target) ->
       >   /nix/store/zxcn56jpdpg0785h4lj4jclbfckbd1zi-msbuild-16.10.1+xamarinxplat.2021.05.26.14.00/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(103,5): error MSB4181: The "Telemetry" task returned false but did not log an error. [/build/FsAutoComplete/test/FsAutoComplete.DependencyManager.Dummy/FsAutoComplete.DependencyManager.Dummy.fsproj]
       >
       >     0 Warning(s)
       >     2 Error(s)
       >
       > Time Elapsed 00:00:00.74
       For full logs, run 'nix log /nix/store/75vwvv1k2kx4ram7bcgshc4h2rkvs1jm-fsac-0.50.0.drv'.

using substituteInPlace :

    postPatch = ''
      substituteInPlace global.json \
      --replace "6.0.100" "5.0.301"
    '';

Which dotnet SDK do you have in the build environment? It’s not 5.0.301. You can run dotnet --list-sdks to find out, if you can get into an environment that has the dotnet command.