DotNET: Difference between revisions
Lord-Valen (talk | contribs) m Use the correct command name. |
|||
| (4 intermediate revisions by 4 users not shown) | |||
| Line 4: | Line 4: | ||
Example build file: | Example build file: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix" line="1" start="1"> | ||
{ | { | ||
, dotnetCorePackages | buildDotnetModule, | ||
, | dotnetCorePackages, | ||
}: | }: | ||
buildDotnetModule | buildDotnetModule { | ||
pname = " | pname = "hello"; | ||
version = " | version = "0.1"; | ||
src = | src = ./.; | ||
projectFile = " | projectFile = "Hello/Hello.csproj"; | ||
dotnet-sdk = dotnetCorePackages.sdk_8_0; | dotnet-sdk = dotnetCorePackages.sdk_8_0; | ||
dotnet-runtime = dotnetCorePackages.runtime_8_0; | dotnet-runtime = dotnetCorePackages.runtime_8_0; | ||
nugetDeps = ./deps. | nugetDeps = ./deps.json; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
If the <code>fetch-deps</code> script isn't working for whatever reason, you can manually run <code>nuget-to- | If the <code>fetch-deps</code> script isn't working for whatever reason, you can manually run <code>nuget-to-json</code>: | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="shell-session"> | ||
dotnet restore --packages=packageDir ./SomeProject.csproj | $ dotnet restore --packages=packageDir ./SomeProject.csproj | ||
nuget-to- | $ nuget-to-json packageDir > deps.json | ||
rm -r packageDir | $ rm -r packageDir | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 120: | Line 109: | ||
If running a .NET-build executable you get the above error, make sure the DOTNET_ROOT environment variable is set: | If running a .NET-build executable you get the above error, make sure the DOTNET_ROOT environment variable is set: | ||
< | <syntaxhighlight lang="nix"> | ||
environment.sessionVariables = { | environment.sessionVariables = { | ||
DOTNET_ROOT = "${pkgs.dotnet-sdk}"; | DOTNET_ROOT = "${pkgs.dotnet-sdk}/share/dotnet/"; | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
See : https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#net-sdk-and-cli-environment-variables | See : https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#net-sdk-and-cli-environment-variables | ||
| Line 213: | Line 202: | ||
== Example: Running Rider with dotnet & PowerShell == | == Example: Running Rider with dotnet & PowerShell == | ||
Rider has better compatibility when run in FHS mode | |||
Rider package | Rider package<syntaxhighlight lang="nix"> | ||
< | |||
pkgs.jetbrains.rider | pkgs.jetbrains.rider | ||
</ | </syntaxhighlight>rider-fhs.nix<syntaxhighlight lang="nix"> | ||
{ pkgs ? import <nixpkgs> {} }: | |||
< | |||
(pkgs.buildFHSEnv { | |||
name = " | name = "rider-env"; | ||
targetPkgs = pkgs: (with pkgs; [ | |||
dotnetCorePackages.dotnet_8.sdk | |||
dotnetCorePackages.dotnet_8.aspnetcore | |||
powershell | powershell | ||
]; | ]); | ||
} | multiPkgs = pkgs: (with pkgs; [ | ||
</ | ]); | ||
runScript = "nohup rider &"; | |||
}).env | |||
</syntaxhighlight><syntaxhighlight lang="nix"> | |||
< | nix-shell ./rider-fhs.nix | ||
nix-shell ./ | </syntaxhighlight>This can be added as an alias to your shell if you update the reference to an absolute address, such as location within your home directory. <syntaxhighlight> | ||
</ | run-rider = "nix-shell ~/nix/rider-fhs.nix"; | ||
</syntaxhighlight> | |||
This can be added as an alias to your shell if you update the reference to an absolute address, such as location within your home directory. | |||
== Example: multi-SDK installation with local workload installation enabled == | == Example: multi-SDK installation with local workload installation enabled == | ||
| Line 264: | Line 244: | ||
* https://learn.microsoft.com/en-us/dotnet/core/introduction | * https://learn.microsoft.com/en-us/dotnet/core/introduction | ||
[[Category:Languages]] | [[Category:Languages]] | ||