I have been struggling with this too, but have found a better solution than the cumbersome nuget package solution. I found this on Stackify. This post only discusses having a separate solution, but it is pretty easy to use only one solution.
Separate Solution For .NET Projects
This options entails having two solution files along with two project files for each project using both .NET core and .NET 4.x.x. First create a fresh blank solution. Next create a new Windows "Class Library" (what you name it does not really matter at this point). Remove this from the solution so you can edit the .csproj file. Open the .csproj file and change the AssemblyName
XML element to the .NET core project assembly name. You should make any other name related changes to the project now. Close the .csproj and rename it to the same as your .xproj file. Copy this to the same folder as the .xproj file.
Now that your new shiny .csproj file is ready, here is where the magic happens. Create a file called ProjectName.project.json
and add this text to it (modify .net framework as necessary)
{ "runtimes": { "win": {} }, "frameworks": { "net461": {} }}
In the .NET 4.x.x solution, reload this modified .csproj and you can add your source files. I found the easiest way to do this is press "Show All Files" and click "Include in Project" in the right-click context menu for each file/folder . Now try to build the .csproj and it should build fine. If this does not build properly, try either reloading the project, or restarting visual studio.
Same Solution, but Two Projects
This is the same as the previous one, however with a few key differences. The name of the .csproj file MUST be different than the name of the .xproj (I just added a suffix, like MyProjectName.win.csproj
and MyProjectName.win.project.json
). These can be added to the same solution without a name conflict. You can even have the AssemblyName
element in the .csproj be the same as the .NET core assembly name, because the output folder changes depending on .NET version
Final Thoughts
I found this solution so much better than the nu-get package option. The only minor thing to think about is all modifications to any references, nu-get packages, or any new files must be added to both projects; This is a small price to pay to avoid the terrible nu-get package option, though. Lets just cross our fingers and hope the VS team can get .xproj references in .cspoj files working as soon as possible.
I know I shouldn't post links, however I would like to give credit where it's due. http://stackify.com/using-both-xproj-and-csproj-with-net-core/
"net451"
to"net46"
so that you use .NET 4.6. Second, make sure that the project you are adding the reference to, uses the same frameworks. MVC usesdnx451
– GregoryHouseMD