Sharing code between a normal .NET library and a Core project did not work for me via simply using a Shared project, because I could not reference it from the Core project.
However, with a little trick I could make it work.
Let me explain with this folder/file structure:
[ProjectName] // Root of Core project
project.json
[ProjectName].xproj
Shared // Root of Shared project
[ProjectName].Shared.projitems
[ProjectName].Shared.shproj
// -- Source files here --
Net // Root of .NET project
[ProjectName].csproj
Properties
AssemblyInfo.cs // For both Core and .NET project
// NO source files here
So, you will need 3 projects, of course: a Core project, a normal .NET project, and a Shared project.
The Shared project has all the source files.
The .NET project references the Shared project, so it also has those files.
The Core project sees all the files the Shared project has, so it also has the same files.
That's it. You now can have common source code files for the .NET and the Core project.
A few notes:
- Do NOT ever put the
.shroj
and the .csproj
into the same folder. For me, it totally turned off intellisense in VS (2015). This information costed a lot of pain for me...
- You can use
#if
-s to fine tune the common code
- You can also use NuGet 2 in the .NET project with the above folder structure.
- Note, that if you'd put the (NuGet 2)
packages.config
into the same folder where the (NuGet 3) project.json
is located, the latter would totally overwrite the earlier.