简体   繁体   中英

.NET and .net core share file among projects

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?

Second question : if Project A is made in .Net and Project B is made in .NET Core , how can we share files without having them to recreate in both projects?

I am using C#

you create cs file in .net project and share the same file in .net core project.

<ItemGroup>
  <Compile Include="..\dotnetproject\somefile.cs" Link="somefile.cs" />
</ItemGroup>

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

It sounds like you are asking for how to add a Linked File reference to a project. If you are using Visual Studio:

  1. Right-click second project (the one that does not contain the file)
  2. Add > Existing Item...
  3. Browse to the file you want to link in
  4. Click the down arrow on the Add button and choose Add As Link

Edit: The original post did not specify whether the two projects exist within the same Visual Studio solution, or two entirely separate solutions / repositories / etc. Linked Files as I described above work for sharing files across projects within the same solution.

For projects that exist in two completely different solutions, git repos, etc, a shared common library is the best approach. Since one of the projects is a .NET Core app, the shared library should be an appropriate NETStandard library. NETStandard libraries can be referenced by both Full Framework .NET and .NET Core applications.

For more details, see:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM