如何在.NET Core项目中引用.NET Framework项目? [英] How do I reference a .NET Framework project in a .NET Core project?

查看:3178
本文介绍了如何在.NET Core项目中引用.NET Framework项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很想开始使用.NET Core,然后慢慢将应用程序和库迁移到它。但是,我无法现实地升级我的整个代码库以使用.NET Core,然后经历测试和在生产环境中部署大量应用程序的过程。

I'd really like to start using .NET Core and slowly migrate applications and libraries to it. However, I can't realistically upgrade my entire code base to use .NET Core and then go through the process of testing and deploying a plethora of applications in production.

例如,如果我创建一个新的.NET Core应用程序并尝试引用我的.NET Framework项目之一,则会得到以下内容:

As an example, if I create a new .NET Core application and try to reference one of my .NET Framework projects I get the following:


不支持以下项目作为参考:-
Foobar.NetFramework具有与当前项目Foobar.NetCore中的
目标不兼容的目标框架。

The following projects are not supported as references: - Foobar.NetFramework has target frameworks that are incompatible with targets in current project Foobar.NetCore.

Foobar.NetCore:.NETCoreApp,Version = v1.0

Foobar.NetCore: .NETCoreApp,Version=v1.0

Foobar.NetFramework:.NETFramework,Version = v4.5

Foobar.NetFramework: .NETFramework,Version=v4.5

是否可以创建一个新的.NET Core应用程序并引用我现有的.NET Framework库?如果是这样,请问该怎么做?我花了数小时浏览Microsoft的文档并在GitHub上搜索他们的问题,但是我找不到任何有关如何实现此目标或他们对该过程的长期愿景有什么正式的解释。

Is it possible to create a new .NET Core application and reference my existing .NET Framework libraries? If so, what's the process for doing that? I've spent hours going through Microsoft's documentation and searching their issues on GitHub, but I can't find anything official on how to achieve this or what their long-term vision is for this process.

推荐答案

是的,我们目前正在尝试相同的操作。诀窍是确保您支持相同的.NET框架。在您的 project.json 文件中,确保该框架与您要包含的项目的框架相匹配。例如:

Yes, we are currently attempting the same thing. The trick is to make sure that you are supporting the same .NET frameworks. Inside your project.json file, make sure the framework matches the framework of the project you wish to include. For example:

"frameworks": {
    "net46": {  --This line here <<<<
      "dependencies": {
        "DomainModel": {
          "target": "project"
        },
        "Models": {
          "target": "project"
        }
      }
    }
  },

仅供参考:您可能需要更改.NET Core或较旧项目的框架才能实现此目的。如上所示,只需编辑project.json文件即可更改.NET Core。在.NET项目中,可以通过右键单击项目并打开属性来实现同样的效果。在这里更改框架级别。

FYI: You might need to change the framework of your .NET Core or your older projects to achieve this. .NET Core can be changed just by editing the project.json file as seen above. You can so the same in .NET projects by right clicking the project and opening properties. Change the framework level there.

一旦您匹配了两个项目框架,则应该能够将它们包括在内。祝你好运!

Once you have matched the two project frameworks then you should be able to include them. Good Luck!

这篇关于如何在.NET Core项目中引用.NET Framework项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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