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

查看:135
本文介绍了如何将.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

如果您的项目在同一解决方案中,那么可以,您可以使用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)

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

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