从 ASP.NET Core MVC Web 应用程序 (RC2) 引用完整的框架库项目?

编程入门 行业动态 更新时间:2024-10-19 16:38:29
本文介绍了从 ASP.NET Core MVC Web 应用程序 (RC2) 引用完整的框架库项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

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

现在,当我尝试使用 Visual Studio 将 Core MVC Web 应用程序的引用添加到完整框架库时,我收到一条错误消息,提示ExampleLib 的目标框架与当前项目 ExampleWebApplicaiton 中的目标不兼容.":

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

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

依赖":{Microsoft.NETCore.App":{版本":1.0.0-rc2-3002702",类型":平台"},

"框架": {netcoreapp1.0":{进口":["dotnet5.6","dnxcore50",便携式-net45+win8"]}},

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

解决方案

有一个模板可以让您以完整的 .NET 框架为目标 - 抱歉,还不能发布图片,但您可以访问:模板 -> Visual C# -> Web -> ASP.NET Core Web 应用程序 (.NET Framework)

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

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

框架":{net461":{}}

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

框架":{net461":{依赖":{类库1":{目标":项目"}}}}

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.

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.

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.

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.

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

So at this point the solution looks like this:

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.":

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.

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" },

or

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

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

解决方案

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)

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

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) 引用完整的框架库项目?

本文发布于:2023-11-15 13:55:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1595037.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   框架   完整   项目   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!