使用 Visual Studio 部署 .NET Core 应用Deploy .NET Core apps with Visual Studio

可将 .NET Core 应用程序部署为依赖框架的部署或独立部署,前者包含应用程序二进制文件,但依赖目标系统上存在的 .NET Core,而后者同时包含应用程序和 .NET Core 二进制文件。You can deploy a .NET Core application either as a framework-dependent deployment, which includes your application binaries but depends on the presence of .NET Core on the target system, or as a self-contained deployment, which includes both your application and .NET Core binaries. 有关 .NET Core 应用程序部署的概述,请参阅 .NET Core 应用程序部署For an overview of .NET Core application deployment, see .NET Core Application Deployment.

以下各节演示如何使用 Microsoft Visual Studio 创建下列各类部署:The following sections show how to use Microsoft Visual Studio to create the following kinds of deployments:

  • 依赖框架的部署Framework-dependent deployment
  • 包含第三方依赖项的依赖框架的部署Framework-dependent deployment with third-party dependencies
  • 独立部署Self-contained deployment
  • 包含第三方依赖项的独立部署Self-contained deployment with third-party dependencies

有关使用 Visual Studio 开发 .NET Core 应用程序的信息,请参阅 .NET Core 依赖项和要求For information on using Visual Studio to develop .NET Core applications, see .NET Core dependencies and requirements.

依赖框架的部署Framework-dependent deployment

如果不使用第三方依赖项,部属依赖框架的部署只包括生成、测试和发布应用。Deploying a framework-dependent deployment with no third-party dependencies simply involves building, testing, and publishing the app. 一个用 C# 编写的简单示例可说明此过程。A simple example written in C# illustrates the process.

  1. 创建项目。Create the project.

    选择“文件” > “新建” > “项目”。Select File > New > Project. 在“新建项目”对话框中,在“已安装”项目类型窗格中展开你的语言的(C# 或 Visual Basic)项目类别,选择“.NET Core”,然后在中心窗格中选择控制台应用 (.NET Core) 模板 。In the New Project dialog, expand your language's (C# or Visual Basic) project categories in the Installed project types pane, choose .NET Core, and then select the Console App (.NET Core) template in the center pane. 在“名称”文本框中输入项目名称,如“FDD”。Enter a project name, such as "FDD", in the Name text box. 选择“确定”按钮。Select the OK button.

  2. 添加应用程序的源代码。Add the application's source code.

    在编辑器中打开 Program.cs 文件或 Program.vb 文件,然后使用下列代码替换自动生成的代码 。Open the Program.cs or Program.vb file in the editor and replace the autogenerated code with the following code. 它会提示用户输入文本,并显示用户输入的个别词。It prompts the user to enter text and displays the individual words entered by the user. 它使用正则表达式 \w+ 来将输入文本中的词分开。It uses the regular expression \w+ to separate the words in the input text.

    using System;
    using System.Text.RegularExpressions;
    
    namespace Applications.ConsoleApps
    {
        public class ConsoleParser
        {
            public static void Main()
            {
                Console.WriteLine("Enter any text, followed by <Enter>:\n");
                String s = Console.ReadLine();
                ShowWords(s);
                Console.Write("\nPress any key to continue... ");
                Console.ReadKey();
            }
    
            private static void ShowWords(String s)
            {
                String pattern = @"\w+";
                var matches = Regex.Matches(s, pattern);
                if (matches.Count == 0)
                {
                    Console.WriteLine("\nNo words were identified in your input.");
                }
                else
                {
                    Console.WriteLine($"\nThere are {matches.Count} words in your string:");
                    for (int ctr = 0; ctr < matches.Count; ctr++)
                    {
                        Console.WriteLine($"   #{ctr,2}: '{matches[ctr].Value}' at position {matches[ctr].Index}");
                    }
                }
            }
        }
    }
    
    Imports System.Text.RegularExpressions
    
    Namespace Applications.ConsoleApps
        Public Module ConsoleParser
            Public Sub Main()
                Console.WriteLine("Enter any text, followed by <Enter>:")
                Console.WriteLine()
                Dim s = Console.ReadLine()
                ShowWords(s)
                Console.Write($"{vbCrLf}Press any key to continue... ")
                Console.ReadKey()
            End Sub
    
            Private Sub ShowWords(s As String)
                Dim pattern = "\w+"
                Dim matches = Regex.Matches(s, pattern)
                Console.WriteLine()   
                If matches.Count = 0 Then
                    Console.WriteLine("No words were identified in your input.")
                Else
                    Console.WriteLine($"There are {matches.Count} words in your string:")
                    For ctr = 0 To matches.Count - 1
                        Console.WriteLine($"   #{ctr,2}: '{matches(ctr).Value}' at position {matches(ctr).Index}")
                    Next
                End If
                Console.WriteLine()
            End Sub
        End Module
    End Namespace
    
    
  3. 创建应用的调试版本。Create a Debug build of your app.

    选择“生成” > “生成解决方案”。Select Build > Build Solution. 也可通过选择“调试” > “开始调试”来编译和运行应用程序的调试版本。You can also compile and run the Debug build of your application by selecting Debug > Start Debugging.

  4. 部署应用。Deploy your app.

    调试并测试程序后,创建要与应用一起部署的文件。After you've debugged and tested the program, create the files to be deployed with your app. 若要从 Visual Studio 发布,请执行以下操作:To publish from Visual Studio, do the following:

    1. 将工具栏上的解决方案配置从“调试”更改为“发布”,生成应用的发布(而非调试)版本。Change the solution configuration from Debug to Release on the toolbar to build a Release (rather than a Debug) version of your app.

    2. 在“解决方案资源管理器”中右键单击项目(而非解决方案),然后选择“发布”。Right-click on the project (not the solution) in Solution Explorer and select Publish.

    3. 在“发布”选项卡上,选择“发布”。In the Publish tab, select Publish. Visual Studio 将包含应用程序的文件写入本地文件系统。Visual Studio writes the files that comprise your application to the local file system.

    4. “发布”选项卡现在显示单个配置文件 FolderProfile。The Publish tab now shows a single profile, FolderProfile. 该配置文件的配置设置显示在选项卡的“摘要”部分。The profile's configuration settings are shown in the Summary section of the tab.

    生成的文件位于 Windows 上名为 Publish 的目录(对于 Unix 系统,是名为 publish 的目录)中的项目 \bin\release\netcoreapp2.1 子目录的子目录中。The resulting files are placed in a directory named Publish on Windows and publish on Unix systems that is in a subdirectory of your project's .\bin\release\netcoreapp2.1 subdirectory.

与应用程序的文件一起,发布过程将发出包含应用调试信息的程序数据库 (.pdb) 文件。Along with your application's files, the publishing process emits a program database (.pdb) file that contains debugging information about your app. 该文件主要用于调试异常。The file is useful primarily for debugging exceptions. 可以选择不使用应用程序文件打包该文件。You can choose not to package it with your application's files. 但是,如果要调试应用的发布版本,则应保存该文件。You should, however, save it in the event that you want to debug the Release build of your app.

可以采用任何喜欢的方式部署完整的应用程序文件集。Deploy the complete set of application files in any way you like. 例如,可以使用简单的 copy 命令将其打包为 Zip 文件,或者使用选择的安装包进行部署。For example, you can package them in a Zip file, use a simple copy command, or deploy them with any installation package of your choice. 安装成功后,用户可通过使用 dotnet 命令或提供应用程序文件名(如 dotnet fdd.dll)来执行应用程序。Once installed, users can then execute your application by using the dotnet command and providing the application filename, such as dotnet fdd.dll.

除应用程序二进制文件外,安装程序还应捆绑共享框架安装程序,或在安装应用程序的过程中将其作为先决条件进行检查。In addition to the application binaries, your installer should also either bundle the shared framework installer or check for it as a prerequisite as part of the application installation. 安装共享框架需要管理员/根访问权限,因为它属于计算机范围。Installation of the shared framework requires Administrator/root access since it is machine-wide.

包含第三方依赖项的依赖框架的部署Framework-dependent deployment with third-party dependencies

要使用一个或多个第三方依赖项来部署依赖框架的部署,需要任何依赖项都可供项目使用。Deploying a framework-dependent deployment with one or more third-party dependencies requires that any dependencies be available to your project. 在生成应用之前,还需执行以下额外步骤:The following additional steps are required before you can build your app:

  1. 使用 NuGet 包管理器向项目添加对 NuGet 包的引用;如果系统上还没有此包,请先安装它。Use the NuGet Package Manager to add a reference to a NuGet package to your project; and if the package is not already available on your system, install it. 要打开包管理器,请选择“工具” > “NuGet 包管理器” > “管理解决方案的 NuGet 包”。To open the package manager, select Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

  2. 确认系统上安装了第三方依赖项(例如,Newtonsoft.Json);如果没有,请安装它们。Confirm that your third-party dependencies (for example, Newtonsoft.Json) are installed on your system and, if they aren't, install them. “已安装”选项卡列出了系统中已安装的 NuGet 包。The Installed tab lists NuGet packages installed on your system. 如果此处未列出 Newtonsoft.Json,请选择“浏览”选项卡,然后在搜索框中输入“Newtonsoft.Json”。If Newtonsoft.Json is not listed there, select the Browse tab and enter "Newtonsoft.Json" in the search box. 选择 Newtonsoft.Json,在右侧窗格中选择项目,然后选择“安装”。Select Newtonsoft.Json and, in the right pane, select your project before selecting Install.

  3. 如果系统中已安装 Newtonsoft.Json,请在“管理解决方案包”选项卡的右侧窗格中选择项目,将其添加到项目。If Newtonsoft.Json is already installed on your system, add it to your project by selecting your project in the right pane of the Manage Packages for Solution tab.

如果依赖框架的部署具有第三方依赖项,则其可移植性只与第三方依赖项相同。A framework-dependent deployment with third-party dependencies is only as portable as its third-party dependencies. 例如,如果某个第三方库只支持 macOS,该应用将无法移植到 Windows 系统。For example, if a third-party library only supports macOS, the app isn't portable to Windows systems. 当第三方依赖项本身取决于本机代码时,也可能发生此情况。This happens if the third-party dependency itself depends on native code. Kestrel 服务器就是一个很好的示例,它需要 libuv 的本机依赖项。A good example of this is Kestrel server, which requires a native dependency on libuv. 当为具有此类第三方依赖项的应用程序创建 FDD 时,已发布的输出会针对每个本机依赖项支持(存在于 NuGet 包中)的运行时标识符 (RID) 包含一个文件夹。When an FDD is created for an application with this kind of third-party dependency, the published output contains a folder for each Runtime Identifier (RID) that the native dependency supports (and that exists in its NuGet package).

不包含第三方依赖项的独立部署Self-contained deployment without third-party dependencies

部署没有第三方依赖项的独立部署包括创建项目、修改 csproj 文件、生成、测试以及发布应用。Deploying a self-contained deployment with no third-party dependencies involves creating the project, modifying the csproj file, building, testing, and publishing the app. 一个用 C# 编写的简单示例可说明此过程。A simple example written in C# illustrates the process. 首先,对项目进行创建、编码及测试,就像对依赖框架的部署的操作一样:You begin by creating, coding, and testing your project just as you would a framework-dependent deployment:

  1. 创建项目。Create the project.

    选择“文件” > “新建” > “项目”。Select File > New > Project. 在“新建项目”对话框中,在“已安装”项目类型窗格中展开你的语言的(C# 或 Visual Basic)项目类别,选择“.NET Core”,然后在中心窗格中选择控制台应用 (.NET Core) 模板 。In the New Project dialog, expand your language's (C# or Visual Basic) project categories in the Installed project types pane, choose .NET Core, and then select the Console App (.NET Core) template in the center pane. 在“名称”文本框中输入项目名称如“SCD”,然后选择“确定”按钮。Enter a project name, such as "SCD", in the Name text box, and select the OK button.

  2. 添加应用程序的源代码。Add the application's source code.

    在编辑器中打开 Program.cs 或 Program.vb 文件,然后使用下列代码替换自动生成的代码 。Open the Program.cs or Program.vb file in your editor, and replace the autogenerated code with the following code. 它会提示用户输入文本,并显示用户输入的个别词。It prompts the user to enter text and displays the individual words entered by the user. 它使用正则表达式 \w+ 来将输入文本中的词分开。It uses the regular expression \w+ to separate the words in the input text.

    using System;
    using System.Text.RegularExpressions;
    
    namespace Applications.ConsoleApps
    {
        public class ConsoleParser
        {
            public static void Main()
            {
                Console.WriteLine("Enter any text, followed by <Enter>:\n");
                String s = Console.ReadLine();
                ShowWords(s);
                Console.Write("\nPress any key to continue... ");
                Console.ReadKey();
            }
    
            private static void ShowWords(String s)
            {
                String pattern = @"\w+";
                var matches = Regex.Matches(s, pattern);
                if (matches.Count == 0)
                {
                    Console.WriteLine("\nNo words were identified in your input.");
                }
                else
                {
                    Console.WriteLine($"\nThere are {matches.Count} words in your string:");
                    for (int ctr = 0; ctr < matches.Count; ctr++)
                    {
                        Console.WriteLine($"   #{ctr,2}: '{matches[ctr].Value}' at position {matches[ctr].Index}");
                    }
                }
            }
        }
    }
    
    Imports System.Text.RegularExpressions
    
    Namespace Applications.ConsoleApps
        Public Module ConsoleParser
            Public Sub Main()
                Console.WriteLine("Enter any text, followed by <Enter>:")
                Console.WriteLine()
                Dim s = Console.ReadLine()
                ShowWords(s)
                Console.Write($"{vbCrLf}Press any key to continue... ")
                Console.ReadKey()
            End Sub
    
            Private Sub ShowWords(s As String)
                Dim pattern = "\w+"
                Dim matches = Regex.Matches(s, pattern)
                Console.WriteLine()   
                If matches.Count = 0 Then
                    Console.WriteLine("No words were identified in your input.")
                Else
                    Console.WriteLine($"There are {matches.Count} words in your string:")
                    For ctr = 0 To matches.Count - 1
                        Console.WriteLine($"   #{ctr,2}: '{matches(ctr).Value}' at position {matches(ctr).Index}")
                    Next
                End If
                Console.WriteLine()
            End Sub
        End Module
    End Namespace
    
    
  3. 确定是否要使用全球化固定模式。Determine whether you want to use globalization invariant mode.

    特别是如果应用面向 Linux,则可以通过利用全球化固定模式来减小部署的总规模。Particularly if your app targets Linux, you can reduce the total size of your deployment by taking advantage of globalization invariant mode. 全球化固定模式适用于不具有全局意识且可以使用固定区域性的格式约定、大小写约定以及字符串比较和排序顺序的应用程序。Globalization invariant mode is useful for applications that are not globally aware and that can use the formatting conventions, casing conventions, and string comparison and sort order of the invariant culture.

    要启用固定模式,右键单击“解决方案资源管理器”中的项目(不是解决方案),然后选择“编辑 SCD.csproj”或“编辑 SCD.vbproj” 。To enable invariant mode, right-click on your project (not the solution) in Solution Explorer, and select Edit SCD.csproj or Edit SCD.vbproj. 然后将以下突出显示的行添加到文件中:Then add the following highlighted lines to the file:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />
      </ItemGroup> 
    
    </Project>
    
  4. 创建应用程序的调试版本。Create a Debug build of your application.

    选择“生成” > “生成解决方案”。Select Build > Build Solution. 也可通过选择“调试” > “开始调试”来编译和运行应用程序的调试版本。You can also compile and run the Debug build of your application by selecting Debug > Start Debugging. 通过此调试步骤,可以识别应用程序在主机平台上运行时出现的问题。This debugging step lets you identify problems with your application when it's running on your host platform. 仍然必须在每个目标平台上对其进行测试。You still will have to test it on each of your target platforms.

    如果已启用全球化固定模式,请特别确保测试缺少对文化敏感的数据是否适合应用程序。If you've enabled globalization invariant mode, be particularly sure to test whether the absence of culture-sensitive data is suitable for your application.

完成调试后,可以发布独立部署:Once you've finished debugging, you can publish your self-contained deployment:

调试并测试程序后,为应用的每个目标平台创建要与应用一起部署的文件。After you've debugged and tested the program, create the files to be deployed with your app for each platform that it targets.

若要从 Visual Studio 发布应用,请执行以下操作:To publish your app from Visual Studio, do the following:

  1. 定义应用的目标平台。Define the platforms that your app will target.

    1. 在“解决方案资源管理器”中右键单击项目(而非解决方案),然后选择“编辑 SCD.csproj” 。Right-click on your project (not the solution) in Solution Explorer and select Edit SCD.csproj.

    2. 在 csproj 文件(该文件用于定义应用的目标平台)的 <PropertyGroup> 部分中创建 <RuntimeIdentifiers> 标记,然后指定每个目标平台的运行时标识符 (RID)。Create a <RuntimeIdentifiers> tag in the <PropertyGroup> section of your csproj file that defines the platforms your app targets, and specify the runtime identifier (RID) of each platform that you target. 还需要添加分号来分隔 RID。You also need to add a semicolon to separate the RIDs. 请查看运行时标识符目录,获取运行时标识符列表。See Runtime identifier catalog for a list of runtime identifiers.

    例如,以下示例表明应用在 64 位 Windows 10 操作系统和 64 位 OS X 10.11 版本的操作系统上运行。For example, the following example indicates that the app runs on 64-bit Windows 10 operating systems and the 64-bit OS X Version 10.11 operating system.

    <PropertyGroup>
       <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
    </PropertyGroup>
    

    <RuntimeIdentifiers> 元素可能会进入 csproj 文件的任何 <PropertyGroup> 中。The <RuntimeIdentifiers> element can go into any <PropertyGroup> that you have in your csproj file. 本节后面部分将显示完整的示例 csproj 文件。A complete sample csproj file appears later in this section.

  2. 发布你的应用。Publish your app.

    调试并测试程序后,为应用的每个目标平台创建要与应用一起部署的文件。After you've debugged and tested the program, create the files to be deployed with your app for each platform that it targets.

    若要从 Visual Studio 发布应用,请执行以下操作:To publish your app from Visual Studio, do the following:

    1. 将工具栏上的解决方案配置从“调试”更改为“发布”,生成应用的发布(而非调试)版本。Change the solution configuration from Debug to Release on the toolbar to build a Release (rather than a Debug) version of your app.

    2. 在“解决方案资源管理器”中右键单击项目(而非解决方案),然后选择“发布”。Right-click on the project (not the solution) in Solution Explorer and select Publish.

    3. 在“发布”选项卡上,选择“发布”。In the Publish tab, select Publish. Visual Studio 将包含应用程序的文件写入本地文件系统。Visual Studio writes the files that comprise your application to the local file system.

    4. “发布”选项卡现在显示单个配置文件 FolderProfile。The Publish tab now shows a single profile, FolderProfile. 该配置文件的配置设置显示在选项卡的“摘要”部分。目标运行时用于标识已发布的运行时,目标位置用于标识独立部署文件的写入位置 。The profile's configuration settings are shown in the Summary section of the tab. Target Runtime identifies which runtime has been published, and Target Location identifies where the files for the self-contained deployment were written.

    5. 默认情况下,Visual Studio 将所有已发布文件写入单个目录。Visual Studio by default writes all published files to a single directory. 为了方便起见,最好为每个目标运行时创建单个配置文件,并将已发布文件置于特定于平台的目录中。For convenience, it's best to create separate profiles for each target runtime and to place published files in a platform-specific directory. 这包括为每个目标平台创建单独的发布配置文件。This involves creating a separate publishing profile for each target platform. 现在,请执行下列操作,为每个平台重新生成应用程序:So now rebuild the application for each platform by doing the following:

      1. 在“发布”对话框中选择“创建新配置文件”。Select Create new profile in the Publish dialog.

      2. 在“选取发布目标”对话框中,将“选择文件夹”位置更改为 bin\Release\PublishOutput\win10-x64。In the Pick a publish target dialog, change the Choose a folder location to bin\Release\PublishOutput\win10-x64. 选择“确定”。Select OK.

      3. 在配置文件列表中选择新配置文件 (FolderProfile1) ,并确保“目标运行时”为 win10-x64Select the new profile (FolderProfile1) in the list of profiles, and make sure that the Target Runtime is win10-x64. 如果不是,请选择“设置”。If it isn't, select Settings. 在“配置文件设置”对话框中,将“目标运行时”更改为 win10-x64,然后选择“保存”。In the Profile Settings dialog, change the Target Runtime to win10-x64 and select Save. 否则,选择“取消”。Otherwise, select Cancel.

      4. 选择“发布”,发布 64 位 Windows 10 平台的应用。Select Publish to publish your app for 64-bit Windows 10 platforms.

      5. 请再次按照上述步骤创建 osx.10.11-x64 平台的配置文件。Follow the previous steps again to create a profile for the osx.10.11-x64 platform. “目标位置”为 bin\Release\PublishOutput\osx.10.11-x64,“目标运行时”为 osx.10.11-x64The Target Location is bin\Release\PublishOutput\osx.10.11-x64, and the Target Runtime is osx.10.11-x64. Visual Studio 分配给此配置文件的名称是 FolderProfile2。The name that Visual Studio assigns to this profile is FolderProfile2.

    每个目标位置中都包含启动应用所需的完整文件集(既包含应用文件,又包含所有 .NET Core 文件)。Each target location contains the complete set of files (both your app files and all .NET Core files) needed to launch your app.

与应用程序的文件一起,发布过程将发出包含应用调试信息的程序数据库 (.pdb) 文件。Along with your application's files, the publishing process emits a program database (.pdb) file that contains debugging information about your app. 该文件主要用于调试异常。The file is useful primarily for debugging exceptions. 可以选择不使用应用程序文件打包该文件。You can choose not to package it with your application's files. 但是,如果要调试应用的发布版本,则应保存该文件。You should, however, save it in the event that you want to debug the Release build of your app.

可按照任何喜欢的方式部署已发布的文件。Deploy the published files in any way you like. 例如,可以使用简单的 copy 命令将其打包为 Zip 文件,或者使用选择的安装包进行部署。For example, you can package them in a Zip file, use a simple copy command, or deploy them with any installation package of your choice.

下面是此项目完整的 csproj 文件。The following is the complete csproj file for this project.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
  </PropertyGroup>
</Project>

包含第三方依赖项的独立部署Self-contained deployment with third-party dependencies

部署包含一个或多个第三方依赖项的独立部署包括添加依赖项。Deploying a self-contained deployment with one or more third-party dependencies involves adding the dependencies. 在生成应用之前,还需执行以下额外步骤:The following additional steps are required before you can build your app:

  1. 使用 NuGet 包管理器向项目添加对 NuGet 包的引用;如果系统上还没有此包,请先安装它。Use the NuGet Package Manager to add a reference to a NuGet package to your project; and if the package is not already available on your system, install it. 要打开包管理器,请选择“工具” > “NuGet 包管理器” > “管理解决方案的 NuGet 包”。To open the package manager, select Tools > NuGet Package Manager > Manage NuGet Packages for Solution.

  2. 确认系统上安装了第三方依赖项(例如,Newtonsoft.Json);如果没有,请安装它们。Confirm that your third-party dependencies (for example, Newtonsoft.Json) are installed on your system and, if they aren't, install them. “已安装”选项卡列出了系统中已安装的 NuGet 包。The Installed tab lists NuGet packages installed on your system. 如果此处未列出 Newtonsoft.Json,请选择“浏览”选项卡,然后在搜索框中输入“Newtonsoft.Json”。If Newtonsoft.Json is not listed there, select the Browse tab and enter "Newtonsoft.Json" in the search box. 选择 Newtonsoft.Json,在右侧窗格中选择项目,然后选择“安装”。Select Newtonsoft.Json and, in the right pane, select your project before selecting Install.

  3. 如果系统中已安装 Newtonsoft.Json,请在“管理解决方案包”选项卡的右侧窗格中选择项目,将其添加到项目。If Newtonsoft.Json is already installed on your system, add it to your project by selecting your project in the right pane of the Manage Packages for Solution tab.

下面是此项目的完整 csproj 文件:The following is the complete csproj file for this project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
  </ItemGroup>
</Project>

部署应用程序时,应用中使用的任何第三方依赖项也包含在应用程序文件中。When you deploy your application, any third-party dependencies used in your app are also contained with your application files. 运行应用的系统上不需要第三方库。Third-party libraries aren't required on the system on which the app is running.

可以只将具有一个第三方库的独立部署部署到该库支持的平台。You can only deploy a self-contained deployment with a third-party library to platforms supported by that library. 这与依赖框架的部署中具有本机依赖项和第三方依赖项相似,其中的本机依赖项不会存在于目标平台上,除非之前在该平台上安装了该依赖项。This is similar to having third-party dependencies with native dependencies in your framework-dependent deployment, where the native dependencies won't exist on the target platform unless they were previously installed there.

请参阅See also