从ASP.NET Core MVC Web应用程序(RC2)引用完整框架库项目吗? [英] Reference a Full Framework Library Project from ASP.NET Core MVC Web Application (RC2)?

查看:34
本文介绍了从ASP.NET Core MVC Web应用程序(RC2)引用完整框架库项目吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用ASP.NET Core MVC RC2,它应该支持从Core MVC Web应用程序项目中引用完整的框架库项目.但我似乎无法使其正常工作.

I'm currently using ASP.NET Core MVC RC2 which is suppose to support referencing a full framework library Project from a Core MVC Web Application Project. But I can't seem to make it work.

我有一个现有的完整框架库项目,希望与新的Core MVC Web应用程序项目一起使用.但是,当我尝试添加对库项目的引用时,出现一个错误,指出该库的目标框架与Web应用程序的目标框架不兼容.

I have an existing full framework library project that I'd like to use with a new Core MVC Web application project. But when I try to add a reference to the library's project I get an error that says the target framework for it is incompatible with the target framework for the web application.

为简化问题,我创建了一个新的Core MVC Web应用程序和一个新的Windows代码库,并尝试将Web应用程序项目中的引用添加到该库的项目中,并得到相同的错误消息.我已经搜索了堆栈溢出问题,但确实找到了这个似乎非常相关的问题:

To try to simplify the problem I created a new Core MVC web application and a new Windows Code Library and tried to add a reference from the web application project to the library's project and got the same error message. I've searched on stack overflow and I did find this question that seemed highly relevent:How to make ASP.NET Core RC2 app build on net46 framework with older third party dependencies but I was unable to use the information there to solve my issue.

以下是重现此问题的步骤:
我创建了一个基于Visual Studio 2015中"Web应用程序"模板的".NET Core""ASP.NET Core Web应用程序"项目的解决方案.

Here are the steps to reproduce the issue:
I created a solution with a ".NET Core" "ASP.NET Core Web Application" project based on the "Web Application" template in Visual Studio 2015.

然后,我向解决方案中添加了一个新的"Windows"类库"项目.

I then added a new "Windows" "Class Library" project to the solution.

因此,此时的解决方案如下所示:

So at this point the solution looks like this:

现在,当我尝试使用Visual Studio将来自Core MVC Web应用程序的引用添加到Full Framework库时,出现一个错误,指出"ExampleLib的目标框架与当前项目ExampleWebApplicaiton中的目标不兼容. :

Now, when I try to use visual studio to add reference from the Core MVC Web Application to the Full Framework library I get an error that says that "ExampleLib has a target frameworks that are incompatible with the targets in current project ExampleWebApplicaiton.":

此错误似乎很容易解释,似乎希望我更改Web应用程序针对的框架,使其与库相同,这是很有意义的.问题是我找不到有关该操作的文档,而智能感知并不是特别有用.

This error seems fairly self explanatory and seems to want me to change the framework that the web application is targeting so that it's the same as the library, which makes perfect sense. The problem is that I can't find documentation on how to do that and intellisense isn't being particularly helpful.

我怀疑我需要为Web应用程序更改以下project.json文件之一:

I suspect I need to change one of the following pieces of the project.json file for the web application:

"dependencies": {
    "Microsoft.NETCore.App": {
     "version": "1.0.0-rc2-3002702",
     "type": "platform"
   },

 "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

如何为Core MVC Web应用程序而不是.NETCoreApp指定.NETFramework 4.6版?

How do I specify .NETFramework Version 4.6 for the Core MVC Web Application instead of .NETCoreApp?

推荐答案

有一个模板,可以让您定位到完整的.NET框架-抱歉,尚不能发布图像,但是您可以转到: 模板-> Visual C#-> Web-> ASP.NET Core Web应用程序(.NET Framework)

There is a template that allows you to target the full .NET framework - sorry, can't post an image yet, but you can go to: Templates -> Visual C# -> Web -> ASP.NET Core Web Application (.NET Framework)

请注意,您可以从上面的下拉列表中指定.NET Framework的版本(照常).

Note that you can specify the version of the .NET Framework from the dropdown above (as per usual).

这会将您的project.json更改为:

This will change your project.json to:

"frameworks": {
"net461": { }
}

(取决于您选择的框架版本).现在,您将可以添加对类库的引用.

(depending on the framework version that you've selected). You will now be able to add a reference to your class library.

"frameworks": {
    "net461": {
    "dependencies": {
    "ClassLibrary1": {
        "target": "project"
        }
     }
   }
}

这篇关于从ASP.NET Core MVC Web应用程序(RC2)引用完整框架库项目吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆