DotNET: Difference between revisions

imported>Basil
m Fixed a typo
imported>Mdarocha
Update notes on global tools
Line 105: Line 105:
== Global Tools ==
== Global Tools ==


There is currently no mechanism to install them globally, and regular (mutable) installation [https://github.com/dotnet/sdk/issues/30546 does not work].
Local instalation of .NET global tools is fully supported and preferred when possible - more info [https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools#install-a-local-tool in the Microsoft docs].


[https://github.com/WhiteBlackGoose/dotfiles/blob/3f7d1b508f75ea87b8f36f3e2be0e2db1f4241c1/envs/dotnet-tool.nix Here] is a proof of concept of how .NET tools could be used declaratively.
For globally installing .NET tools, search if they are available as Nix packages - they are packaged as any other normal
.NET binary, using <code>buildDotnetModule</code>. For .NET tools with no source available, or those hard to build from source, <code>buildDotnetGlobalTool</code> is available. See [https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/dotnet.section.md#dotnet-global-tools-dotnet-global-tools dotnet nixpkgs manual] for more info.


Here's an example of using that package:
Note that Nix-packaged .NET tools use a special wrapper (toggled by <code>useDotnetFromEnv</code> option in <code>buildDotnetModule</code>) that automatically picks up .NET install from the user environment. If you want to use a
 
different SDK version with a Nix-packaged .NET tools than the default, make sure the <code>dotnet</code> CLI is installed and available.
<syntaxHighlight lang=nix>
packages =                                                       
  let dotnetPkg =                                               
    (with dotnetCorePackages; combinePackages [                 
      sdk_7_0                                                   
      sdk_6_0                                                   
    ]);                                                         
    dotnetTools = (callPackage ./dotnet-tool.nix {});    # dotnet-tool.nix is the file from the link above
  in [                                                           
    vim                                                         
    firefox                                                     
    dotnetPkg                                                   
    dotnetTools.combineTools dotnetPkg (with dotnetTools.tools; [
                          #  ^^^^^^^^^ here we specify the dotnet package
                          # that will be invoked for this tool
                          # Ideally, something like dotnetPkg.withTools
                          # should be there
 
      fsautocomplete                                      # these are tools from dotnetTools.tools;       
      csharp-ls                                          # if a package is missing, it can be declared
      dotnet-repl                                        # manually, see the sources of dotnet-tools.nix
    ])                                                           
  ];                                                             
</syntaxHighlight>


== See also ==
== See also ==