简体   繁体   中英

Legacy assembly reference error in asp.net-vnext

I am using VS2015 CTP5 and I am referencing a legacy class library compiled with 4.5.1. During compile, I get this warning:

The primary reference "D:\\components.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".

Here is my project.json after adding the reference

"frameworks": {
    "aspnet50": {
        "dependencies": {
            "components": "1.0.0-*"
        }
    }
},

Since the "component" library is build for .net 45 and assuming that you build that library in an older version of visual studio, it will not work in aspnetcore5 but will work on aspnet5 (these are the new version for .net). if you want to get rid of the error and still use your component library, you will need remove the aspnetcore5 json node from the project.json file but the project that you building will not be compatible with aspnetcore5. So your project.json file for the frameworks section should look like this.

"frameworks": {
    "aspnet50": {

        "frameworkAssemblies": {
            "System": "4.0.0.0"
        },
        "dependencies": {


        }
    },      
    "net45": {
        "dependencies": {  "components": "1.0.0"},
        "frameworkAssemblies": { }

    }

}

And your reference should look like, I have warning sing next to the component library because I don't have that in my code.

You can look at this question to get more information.

Question 1 , Question 2

Add the library to frameworkDependencies not dependencies

"net45": {
    "frameworkAssemblies": {
        "components": "1.0.0"
    },
    "dependencies": {
        // NuGet packages go here
    }

For me, none of the above worked and after spending a lot of hours investigating... I finally found a solution!

I have to create a new package in the NuGet Package Explorer for my dll, save and export it to a local folder (use the File->Save and File->Export commands). Then declare my local repository(folder) to Visual Studio, go to Tools->Options->NuGet Package Manager->Package Sources and insert a record for my local repository - see image below.

VS2015中的包源

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