.net核心类库,调用.net框架类库 [英] .net core classlibrary calling .net framework class library

查看:149
本文介绍了.net核心类库,调用.net框架类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找不到我的疑问的答案,希望有人可以澄清。

Could not find an answer to my doubts and hopefully somebody can clarify.

我用


  • 1个类库(.net框架)

  • 1个.net核心库

尝试以任何一种方式进行引用,但我不能,它们不兼容,很好,很有意义。

Tried to reference either way but I cant,they are not compatible,fine makes sense.

现在我的问题

我有一个实用程序类库(.net框架),带有扩展名,帮助程序等...
现在由winforms-wpf-asp.net mvc 4,5个应用程序使用.net核心事件在我看来,除非将其移植到.net核心,否则我将无法再使用此库,然后我就无法与其他应用程序一起使用。

I have a utility class library(.net framework)with extensions,helpers etc... that is used by winforms-wpf-asp.net mvc 4,5 apps now with the event of .net core it looks to me that I cannot use this library anymore unless I port it to .net core,which then i cannot use with my other apps.

正确的方法是什么?

我错过了明显的地方吗?

Am i missing the obvious?

推荐答案

在普通的.NET库和Core项目之间共享代码对我来说不起作用,仅通过使用Shared项目即可,因为我无法从Core项目中引用它。

Sharing code between a normal .NET library and a Core project did not work for me via simply using a Shared project, because I could not reference it from the Core project.

不过,我可以通过一点技巧使它工作。

However, with a little trick I could make it work.

让我用以下文件夹/文件结构进行解释:

Let me explain with this folder/file structure:

[ProjectName] // Root of Core project
    project.json
    [ProjectName].xproj

    Shared // Root of Shared project
        [ProjectName].Shared.projitems
        [ProjectName].Shared.shproj 
        // -- Source files here --

    Net // Root of .NET project
        [ProjectName].csproj
        Properties
            AssemblyInfo.cs // For both Core and .NET project
        // NO source files here

因此,您当然需要3个项目:一个Core项目,一个普通的.NET项目和一个共享项目。

共享项目具有所有源文件。

.NET项目引用共享项目,因此它也具有这些文件。
/>
Core项目会看到Shared项目拥有的所有文件,因此它也具有相同的文件s。

So, you will need 3 projects, of course: a Core project, a normal .NET project, and a Shared project.
The Shared project has all the source files.
The .NET project references the Shared project, so it also has those files.
The Core project sees all the files the Shared project has, so it also has the same files.

就是这样。现在,您可以拥有.NET和Core项目的通用源代码文件。

That's it. You now can have common source code files for the .NET and the Core project.

一些注意事项:

A few notes:


  • 切勿放置 .shroj .csproj 放入同一文件夹。对我而言,它在VS(2015)中完全关闭了智能感知功能。此信息使我痛苦不堪...

  • 您可以使用 #if -s进行微调常见代码

  • 您也可以在具有上述文件夹结构的.NET项目中使用NuGet2。



    • 请注意,如果将(NuGet 2) packages.config 放在(NuGet 3)<$ c $所在的文件夹中c> project.json 位置,后者将完全覆盖前者。

    • Do NOT ever put the .shroj and the .csproj into the same folder. For me, it totally turned off intellisense in VS (2015). This information costed a lot of pain for me...
    • You can use #if -s to fine tune the common code
    • You can also use NuGet 2 in the .NET project with the above folder structure.
      • Note, that if you'd put the (NuGet 2) packages.config into the same folder where the (NuGet 3) project.json is located, the latter would totally overwrite the earlier.

      这篇关于.net核心类库,调用.net框架类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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