且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将.NET Core项目导入到Visual Studio中的另一个.NET Core项目?

更新时间:2022-12-03 15:48:55

.NET Core 通过 NuGet

如果您的项目在同一解决方案中,那么可以,您可以使用Visual Studio UI添加引用(添加引用命令)。背景参考将作为NuGet包添加。

If your projects are in the same solution, then yes, you can add a reference using the Visual Studio UI ("Add reference" command). A background reference will be added as a NuGet package.

您可以通过在 .csproj中添加< ProjectReference> 部分来手动执行此操作。 文件:

Manually you can do this by adding <ProjectReference> section to the .csproj file:

<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />

否则,您应该将项目打包到NuGet包中(使用 dotnet pack 命令),然后将其添加为其他NuGet程序包。
如果您不使用任何公共NuGet来源,则可以主机您自己的NuGet提要

Otherwise, you should pack your project into a NuGet package (use the dotnet pack command) and then add it as other NuGet packages. If you do not use any public NuGet sources, you can host your own NuGet feed.

您遇到下一个错误:

".NET Core projects only support referencing .NET framework assemblies in this release.
 To reference other assemblies they need to be included in a NuGet package"

因为您正在尝试将.NET项目添加到.NET Core项目,反之亦然。请查看此问题以了解更多详细信息:

Because you are trying to add a .NET project to a .NET Core project or wise versa. Look into this issue for more details:


  • 如果您使用的是netcoreapp,则无法使用.NET 4.x
    程序集/软件包

  • 如果使用的是net4xx那么您可以使用project.json的frameworkAssemblies
    部分来引用
    .NET Framework安装的DLL文件( GAC

  • If you're using netcoreapp then you cannot use .NET 4.x assemblies/packages
  • If you're using net4xx then you can use the frameworkAssemblies section of project.json to reference DLL files that are installed by .NET Framework (the stuff in the GAC)