8

I need to use some classes from another project. How can I just import or create a reference to that project in 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"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Serhii Shemshur
  • 1,273
  • 3
  • 15
  • 21

3 Answers3

14

.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)
Set
  • 47,577
  • 22
  • 132
  • 150
  • Thanks. But I can't use Add reference in VS. I have 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" – Serhii Shemshur Jul 13 '16 at 09:17
0

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.

Harry .Naeem
  • 1,245
  • 3
  • 20
  • 33
0

You can add reference by adding your project name in csproj file. if your project in same solution

<ItemGroup>
<ProjectReference Include="..\projectName.csproj" />
<ProjectReference Include="..\ProjectName2.csproj" />
<ProjectReference Include="..\ProjectName3.csproj" />
Zahid Hasan
  • 365
  • 3
  • 5