.NET and .net core share file among projects

Sar*_*rah 5 .net c# asp.net-core

We have some .cs files in our project A that are needed in Project B.

First question: how do I share the files across projects without recreating them in the other project?

第二个问题:如果项目 A 是在 中制作的.Net,项目 B 是在 中制作的.NET Core,我们如何共享文件而不需要在两个项目中重新创建它们?

我正在使用 C#

div*_*481 0

您在 .net 项目中创建 cs 文件并在 .net core 项目中共享相同的文件。

<ItemGroup>
  <Compile Include="..\dotnetproject\somefile.cs" Link="somefile.cs" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

https://andrewlock.net/include-linked-files-from-outside-the-project-directory-in-asp-net-core/