简体   繁体   中英

Add reference to ASP.NET 5 Class Library from Framework 4.5 Class Library Project

I want to add reference to ASP.NET 5 Class Library project from regular Framework 4.5 Class Library Project. I cannot do it. Is there some workaround and will this be supported? I have tried to add dependency to framework 4.5 in project.json like this:

 "frameworks": {

        "net451": {
            "dependencies": {
                 "System.Data.Common": "1.0.0-beta1",
                "System.Data.SqlClient": "1.0.0-beta1"
            },
            "frameworkAssemblies": {

            }

        },

And after this add reference to this ASP.NET 5 Class Library project but without success.

check the "Produce outputs on build" checkbox will copy build outputs to artifacts\\bin\\[CONFIGURATION]\\[FRAMEWORK] folder

在此处输入图片说明

then you can reference this dll

You can do it! First we need to understand that "old-style" projects output and reference DLLs. The ASP.NET 5 projects output and reference NuGet packages.

First set up a local nuget repository. Luckily this can be a folder. Then add that to folder NuGet.Config file.

<config>
 <add key="localrepo" value="C:\Temp" />
 <the rest of your file />
</config>

You can also do this through the Tools -> Options -> NuGet Package Manager -> Package Sources window in Visual Studio.

Then navigate your commandline to the ASP.NET 5 class library you want to reference. Drag down the dependencies with

kpm restore

Then build and pack it and output the result to your local repository folder.

kpm pack --out C:\Temp

Now you should be able to add the nupkg from kpm pack as a nuget reference in your "old style" project. Use your normal way of Managing NuGet Packages from Visual Studio if you wish.

Note: Your ASP.NET 5 class library needs to target net45 for this to work. Make sure this is in the framework section of your project.json

...
"frameworks": {
        "net45": {},
        // Other frameworks
  }
...

Alternatively: If you want to do it quick and dirty you can run

kpm build

, and add a direct DLL reference. The DLLs location should be listen in the output from kpm build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM