DotNET: Difference between revisions
imported>Milahu m fixup NETSDK1013, project will build only on Windows |
imported>Mdarocha Modernize the wiki page, removing references to the old deprecated buildDotnetPackage and adding references to buildDotnetModule |
||
Line 1: | Line 1: | ||
.NET packages can be built with <code> | .NET packages can be built with <code>buildDotnetModule</code> | ||
More information about <code>buildDotnetModule</code> can be found in the [https://nixos.org/manual/nixpkgs/unstable/#dotnet nixpkgs manual] | |||
Example build file: | Example build file: | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
{ | { fetchFromGitHub | ||
, buildDotnetModule | |||
, | |||
}: | }: | ||
buildDotnetModule rec { | |||
pname = "some_program"; | pname = "some_program"; | ||
version = "some_version"; | version = "some_version"; | ||
Line 23: | Line 20: | ||
}; | }; | ||
projectFile = "SomeProject/SomeProject.csproj" | |||
meta = with lib; { | meta = with lib; { | ||
Line 48: | Line 28: | ||
}; | }; | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
= | Note that the above package will not build the first time. After adding the above definition to `all-packages.nix`, you | ||
can run the package-specific `fetch-deps` script, which will generate a file containing all the nuget dependencies of the | |||
package. Build the script with <code>nix-build -A some-package.fetch-deps</code>, copy that generated file (the location will be printed by the script) and set the <code>nugetDeps</cude> attribute in <code>buildDotnetModule</code> to point to that generated file (ie. <code>nugetDeps = ./deps.nix</code>). | |||
< | After that the package will build normally. Remember to re-run <code>fetch-deps</code> every time the package is updated. | ||
== Building non-.NET Core packages == | |||
Keep in mind that building non-.NET Core projects (ie. projects that don't build using the <code>dotnet</code> CLI tool) is not well supported. For those projects, you have to work on a custom derivation or override the <code>buildDotnetModule</code> build steps. | |||
== .NET location: Not found == | == .NET location: Not found == | ||
set | If running a .NET-build executable you get the above error, make sure the DOTNET_ROOT environment variable is set: | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
environment.sessionVariables = { | environment.sessionVariables = { | ||
Line 136: | Line 61: | ||
Wontfix: The project will build only on Windows. | Wontfix: The project will build only on Windows. | ||
== NativeAOT == | == NativeAOT == | ||
Line 238: | Line 139: | ||
* [https://ryantm.github.io/nixpkgs/languages-frameworks/dotnet/ dotnet in the nixpkgs manual] | * [https://ryantm.github.io/nixpkgs/languages-frameworks/dotnet/ dotnet in the nixpkgs manual] | ||
* [https://grep.app/search?q=buildDotnetPackage&filter%5Brepo%5D%5B0%5D=NixOS/nixpkgs&filter%5Blang%5D%5B0%5D=Nix&filter%5Bpath%5D%5B0%5D=pkgs/ buildDotnetPackage references in nixpkgs] | * [https://grep.app/search?q=buildDotnetPackage&filter%5Brepo%5D%5B0%5D=NixOS/nixpkgs&filter%5Blang%5D%5B0%5D=Nix&filter%5Bpath%5D%5B0%5D=pkgs/ buildDotnetPackage references in nixpkgs] | ||
* [https://sgt.hootr.club/molten-matter/dotnet-on-nix/ The journey of packaging a .NET app on Nix] | * [https://sgt.hootr.club/molten-matter/dotnet-on-nix/ The journey of packaging a .NET app on Nix] | ||
* https://en.wikipedia.org/wiki/.NET_Framework | * https://en.wikipedia.org/wiki/.NET_Framework - The old, windows-only version of .NET. Newer versions (ie. .NET Core) are multiplatform. | ||
** https://en.wikipedia.org/wiki/Mono_(software) is the deprecated open source implementation of the DotNET compiler and runtime. It has transformed into .NET Core. | |||
* https://learn.microsoft.com/en-us/dotnet/core/introduction | |||
** https://en.wikipedia.org/wiki/List_of_CLI_languages: C#, [[Fsharp|F#]], Visual Basic, ... | ** https://en.wikipedia.org/wiki/List_of_CLI_languages: C#, [[Fsharp|F#]], Visual Basic, ... | ||
[[Category: Development]] | [[Category: Development]] |