Reference a .NET Core Library in a .NET 4.6 project

后端 未结 5 1091
夕颜
夕颜 2020-11-30 00:11

Maybe I have a miss understanding of what \".NET Core Library\" means, but when I try to add a .NET Core Library in a .NET 4.6 Assembly using Visual Studio 2015, I get the e

5条回答
  •  暖寄归人
    2020-11-30 01:14

    I found a very simple solution that works well, if you don't mind hardcoding a reference to either Debug or Release. You just manually add a reference to your xproj in the csproj file. Here is how you do it:

    1. Ensure that your csproj is using at least one nuget package. Most projects do, so this is not a problem.
    2. In Visual Studio, unload your csproj project
    3. In Visual Studio, right-click on the csproj file and choose "edit"
    4. Find the part in the csproj project file where you are referencing a nuget package. Ah... here's one:

           
             ..\packages\Microsoft.CodeAnalysis.Common.1.3.0\lib\net45\Microsoft.CodeAnalysis.dll
             True
          
      
    5. Copy this and modify it to reference the DLL produced by your xproj project, like so:

        
           ..\HighFive.Server.Web\bin\Debug\net461\HighFive.Server.Web.dll
           True
       
      
    6. Save and close the csproj file
    7. Reload the project
    8. Rebuild all
    9. Presto!

    Regarding hardcoding either a Debug or Release reference: For unit test projects, this is not a problem since you typically execute unit tests in debug mode. I am sure this could be made even smarter using MSBuild parameters to avoid the hardcoding but I didn't need to do it yet.

提交回复
热议问题