How do I import a .NET Core project to another .NET Core project in Visual Studio?

一笑奈何 提交于 2019-11-29 07:08:29

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

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

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

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.

You have the next error:

".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"

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

  • 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)

I had a .Net core project and i wanted to create another project for services in my solution. After adding the project I added the reference as follows:

  1. Right click Dependencies in your solution.
  2. Select Add Reference option.
  3. In the next window, in Projects dropdown select the project you want to add.

Alternatively, you can add a reference by editing the csproj file of the project in which you want to add the dependency/reference. Open the file and add the following:

<ItemGroup>
   <ProjectReference Include="..\PATH\TO_YOUR_NEW PROJECT.csproj" />
</ItemGroup>

Hope this helps someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!