如何将 .NET Core 项目导入 Visual Studio 中的另一个 .NET Core 项目? [英] How do I import a .NET Core project to another .NET Core project in Visual Studio?

查看:38
本文介绍了如何将 .NET Core 项目导入 Visual Studio 中的另一个 .NET Core 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用另一个项目中的一些类.如何在 Visual Studio 中导入或创建对该项目的引用?

I need to use some classes from another project. How can I just import or create a reference to that project in Visual Studio?

现在如果我在 Visual Studio 中使用添加引用",我会收到错误:

Right now if I use "Add reference" in Visual Studio, I get the error:

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

推荐答案

.NET Core 通过 NuGet 处理依赖项.

.NET Core works with dependencies via 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.

您可以手动将 <ProjectReference> 部分添加到 .csproj 文件:

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

<ProjectReference Include="..ClassLibrary1ClassLibrary1.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,那么您可以使用 frameworkAssembliesproject.json 的部分以引用由安装的 DLL 文件.NET 框架(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)

这篇关于如何将 .NET Core 项目导入 Visual Studio 中的另一个 .NET Core 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆