DotNET: Difference between revisions

From NixOS Wiki
imported>Milahu
add missing NuGet packages
imported>Milahu
code formatting
Line 61: Line 61:


<blockquote>
<blockquote>
<code>
<nowiki>
error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ../../packages/Microsoft.Bcl.Build.1.0.21/build/Microsoft.Bcl.Build.targets.
error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ../../packages/Microsoft.Bcl.Build.1.0.21/build/Microsoft.Bcl.Build.targets.
</nowiki>
</code>
</blockquote>
</blockquote>


Line 69: Line 73:


<blockquote>
<blockquote>
<code>
&lt;Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" /&gt;
&lt;Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" /&gt;
</code>
</blockquote>
</blockquote>



Revision as of 15:53, 1 March 2022

dotnet packages can be built with buildDotnetPackage

example build file:

/*
some_program/default.nix
nix-build -E 'with import <nixpkgs> { }; callPackage ./default.nix { }'
*/

{ lib
, stdenv
, fetchFromGitHub
, buildDotnetPackage
, dotnetPackages
, pkg-config
}:

buildDotnetPackage rec {
  pname = "some_program";
  baseName = pname; # workaround for "called without baseName"
  version = "some_version";
  src = fetchFromGitHub {
    owner = "some_owner";
    repo = pname;
    rev = "v${version}";
    sha256 = ""; # todo
  };
  projectFile = ["path/to/some_project.csproj"];
  propagatedBuildInputs = [
  ];
  buildInputs = [
    # unit tests
    dotnetPackages.NUnit
    dotnetPackages.NUnitRunners
  ];
  nativeBuildInputs = [
    pkg-config
  ];
  meta = with lib; {
    homepage = "some_homepage";
    description = "some_description";
    license = licenses.mit;
  };
}

XML namespace error

The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.

TODO

missing NuGet packages

example error:

error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ../../packages/Microsoft.Bcl.Build.1.0.21/build/Microsoft.Bcl.Build.targets.

these are upstream bugs

as workaround, patch *.csproj files, to remove all XML tags that contain the "missing file" paths, for example

<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />

see also https://stackoverflow.com/questions/32254439/nuget-packages-are-missing

See also