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

查看:78
本文介绍了如何在 .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 库?如果是这样,这样做的过程是什么?我花了几个小时浏览微软的文档并在 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 或旧项目的框架才能实现此目的..NET Core 可以通过编辑 project.json 文件来更改,如上所示.您可以通过右键单击项目并打开属性在 .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天全站免登陆