How to include source files of one project in another project?

送分小仙女□ 提交于 2019-12-05 04:21:39

One option is to use the Add As Link options mentioned by the others already, but you have more options than that:

  1. Portable Class Libraries are a special kind of project that allow you to specify which versions of .NET you want to target. The compiler then outputs the respective assemblies for you. The advantage of this technique is that you have one version of the source that compiles to both frameworks. The disadvantage is that you can't use features that the lowest common denominator .NET framework doesn't support.
  2. Source control branching & merging allow you to actually maintain 2 similar but different source files. You have one version that is the master version, then after applying a change to it, you merge it to your projects that produce the actual output. The advantage of this technique is that you can have two completely separate files, so you have a lot of freedom. The disadvantage is that you have two completely separate files, which can be hard to manage.
  3. Do better MsBuild trickery. Using the <choose>/<when> construct you can conditionally include references to a specific assembly version depending on a condition. The target framework version and other fancy settings can also be managed through MsBuild, but you can't always edit these through the UI. You can use this in combination with #if MY_CONSTANT to create conditionally compiled parts of the application
  4. You can create a .NET Assembly that you reference from both projects. You set the .NET version to the lowest version, 3.5 in your case. Visual Studio 2010 and later have multi-targeting support and you can mix and match .NET framework versions in one solution.

What kind of qircks are you running into, if you share (part of) your project files, we might be able to resolve those for you.

You can use the Add as Link feature.

It goes like this:

  • Right-click where you need your (existing) file to be
  • "Add" -> "Existing Item"
  • Select your file then click the arrow on the "Add" button and choose "Add As link" (see screenshot below)
  • A link to the file will be added to the project instead of a copy

When adding file to project choose "Add as link" not just add.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!