buildDotnetModule: support local project references
This commit is contained in:
parent
a6d02a5214
commit
06477cccf7
@ -74,6 +74,16 @@ To package Dotnet applications, you can use `buildDotnetModule`. This has simila
|
|||||||
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. This can be an array of multiple projects as well.
|
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. This can be an array of multiple projects as well.
|
||||||
* `nugetDeps` has to be used to specify the NuGet dependency file. Unfortunately, these cannot be deterministically fetched without a lockfile. This file should be generated using `nuget-to-nix` tool, which is available in nixpkgs.
|
* `nugetDeps` has to be used to specify the NuGet dependency file. Unfortunately, these cannot be deterministically fetched without a lockfile. This file should be generated using `nuget-to-nix` tool, which is available in nixpkgs.
|
||||||
* `packNupkg` is used to pack project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`.
|
* `packNupkg` is used to pack project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`.
|
||||||
|
* `projectReferences` can be used to resolve `ProjectReference` project items. Referenced projects can be packed with `buildDotnetModule` by setting the `packNupkg = true` attribute and passing a list of derivations to `projectReferences`. Since we are sharing referenced projects as NuGets they must be added to csproj/fsproj files as `PackageReference` as well.
|
||||||
|
For example, your project has a local dependency:
|
||||||
|
```xml
|
||||||
|
<ProjectReference Include="../foo/bar.fsproj" />
|
||||||
|
```
|
||||||
|
To enable discovery through `projectReferences` you would need to add:
|
||||||
|
```xml
|
||||||
|
<ProjectReference Include="../foo/bar.fsproj" />
|
||||||
|
<PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/>
|
||||||
|
```
|
||||||
* `executables` is used to specify which executables get wrapped to `$out/bin`, relative to `$out/lib/$pname`. If this is unset, all executables generated will get installed. If you do not want to install any, set this to `[]`.
|
* `executables` is used to specify which executables get wrapped to `$out/bin`, relative to `$out/lib/$pname`. If this is unset, all executables generated will get installed. If you do not want to install any, set this to `[]`.
|
||||||
* `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies.
|
* `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies.
|
||||||
* `buildType` is used to change the type of build. Possible values are `Release`, `Debug`, etc. By default, this is set to `Release`.
|
* `buildType` is used to change the type of build. Possible values are `Release`, `Debug`, etc. By default, this is set to `Release`.
|
||||||
@ -93,7 +103,9 @@ Here is an example `default.nix`, using some of the previously discussed argumen
|
|||||||
```nix
|
```nix
|
||||||
{ lib, buildDotnetModule, dotnetCorePackages, ffmpeg }:
|
{ lib, buildDotnetModule, dotnetCorePackages, ffmpeg }:
|
||||||
|
|
||||||
buildDotnetModule rec {
|
let
|
||||||
|
referencedProject = import ../../bar { ... };
|
||||||
|
in buildDotnetModule rec {
|
||||||
pname = "someDotnetApplication";
|
pname = "someDotnetApplication";
|
||||||
version = "0.1";
|
version = "0.1";
|
||||||
|
|
||||||
@ -101,6 +113,7 @@ buildDotnetModule rec {
|
|||||||
|
|
||||||
projectFile = "src/project.sln";
|
projectFile = "src/project.sln";
|
||||||
nugetDeps = ./deps.nix; # File generated with `nuget-to-nix path/to/src > deps.nix`.
|
nugetDeps = ./deps.nix; # File generated with `nuget-to-nix path/to/src > deps.nix`.
|
||||||
|
projectReferences = [ referencedProject ]; # `referencedProject` must contain `nupkg` in the folder structure.
|
||||||
|
|
||||||
dotnet-sdk = dotnetCorePackages.sdk_3_1;
|
dotnet-sdk = dotnetCorePackages.sdk_3_1;
|
||||||
dotnet-runtime = dotnetCorePackages.net_5_0;
|
dotnet-runtime = dotnetCorePackages.net_5_0;
|
||||||
|
@ -30,6 +30,15 @@
|
|||||||
# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
|
# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
|
||||||
# This can be generated using the `nuget-to-nix` tool.
|
# This can be generated using the `nuget-to-nix` tool.
|
||||||
, nugetDeps ? null
|
, nugetDeps ? null
|
||||||
|
# A list of derivations containing nupkg packages for local project references.
|
||||||
|
# Referenced derivations can be built with `buildDotnetModule` with `packNupkg=true` flag.
|
||||||
|
# Since we are sharing them as nugets they must be added to csproj/fsproj files as `PackageReference` as well.
|
||||||
|
# For example, your project has a local dependency:
|
||||||
|
# <ProjectReference Include="../foo/bar.fsproj" />
|
||||||
|
# To enable discovery through `projectReferences` you would need to add a line:
|
||||||
|
# <ProjectReference Include="../foo/bar.fsproj" />
|
||||||
|
# <PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/>
|
||||||
|
, projectReferences ? []
|
||||||
# Libraries that need to be available at runtime should be passed through this.
|
# Libraries that need to be available at runtime should be passed through this.
|
||||||
# These get wrapped into `LD_LIBRARY_PATH`.
|
# These get wrapped into `LD_LIBRARY_PATH`.
|
||||||
, runtimeDeps ? []
|
, runtimeDeps ? []
|
||||||
@ -64,6 +73,7 @@ let
|
|||||||
inherit sha256;
|
inherit sha256;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
_localDeps = linkFarmFromDrvs "${name}-local-nuget-deps" projectReferences;
|
||||||
|
|
||||||
nuget-source = stdenvNoCC.mkDerivation rec {
|
nuget-source = stdenvNoCC.mkDerivation rec {
|
||||||
name = "${args.pname}-nuget-source";
|
name = "${args.pname}-nuget-source";
|
||||||
@ -76,6 +86,8 @@ let
|
|||||||
|
|
||||||
nuget sources Add -Name nixos -Source "$out/lib"
|
nuget sources Add -Name nixos -Source "$out/lib"
|
||||||
nuget init "${_nugetDeps}" "$out/lib"
|
nuget init "${_nugetDeps}" "$out/lib"
|
||||||
|
${lib.optionalString (projectReferences != [])
|
||||||
|
"nuget init \"${_localDeps}\" \"$out/lib\""}
|
||||||
|
|
||||||
# Generates a list of all unique licenses' spdx ids.
|
# Generates a list of all unique licenses' spdx ids.
|
||||||
find "$out/lib" -name "*.nuspec" -exec sh -c \
|
find "$out/lib" -name "*.nuspec" -exec sh -c \
|
||||||
|
Loading…
Reference in New Issue
Block a user