Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import a .NET Core project to another .NET Core project in 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?

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"
like image 970
Serhii Shemshur Avatar asked Jul 13 '16 08:07

Serhii Shemshur


People also ask

Can you mix .NET and .NET Core?

NET Standard support - it can't, as it doesn't even support async/await . You need to upgrade to . NET 4.6.

How do I move .NET framework to .NET Core?

Move Your Project File You can migrate your old project to the Core project using the 'dotnet migrate; command, which migrates the project. json and any other files that are required by the web application. The dotnet migrate command will not change your code in any way.


1 Answers

.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)
like image 131
Set Avatar answered Nov 17 '22 18:11

Set