C# 依赖项未包含在发布中

C# dependecies aren't being included with publish

我正在尝试将 .NET Core 中内置的 Web API 发布到 Ubuntu 服务器,但我在依赖项方面遇到困难。我不熟悉在 C# 中执行此操作,还没有找到关于如何将依赖项包含在发布命令中的简明答案。我被引导相信他们被编译成 .dll 但是当 运行 我的应用程序

时我收到了这个错误
Error:
An assembly specified in the application dependencies manifest (api.deps.json) was not found:
    package: 'Newtonsoft.Json', version: '11.0.2'
    path: 'lib/netstandard2.0/Newtonsoft.Json.dll'

发布后不应该包含在"Release"目录中吗?

我在 Mac 上使用 .NET Core,然后发布到 Ubuntu 服务器应该会影响这里的任何内容。

.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  </ItemGroup>

</Project>

Shouldn't that have been included in the "Release" directory after being published?

没有。

发布项目时,您在创建发布配置文件时为发布输出指定了不同的目录。

Release 目录仅用于调试期间使用的资产。在开发过程中,NuGet 依赖项不在 Release 文件夹中,它们在 NuGet 缓存中。因此,您不能总是只复制 Release 文件夹并期望它到 运行。

发布后,整个应用程序(包括所有依赖项)都会输出到发布位置。请注意,发布输出不一定是文件夹。例如,根据项目类型,它可能会通过 Web 部署发布到 IIS 或 FTP 位置。