将ProjectReference添加到不在同一解决方案中的项目 [英] Adding a ProjectReference to a project that is not in the same solution

查看:674
本文介绍了将ProjectReference添加到不在同一解决方案中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对我们的项目和解决方案文件进行一些重构时,我分离了一些.sln文件以包含更少的项目.

While doing some refactoring of our projects and solution files, i have separated some .sln files to contain less projects.

有时,我需要从当前.sln文件范围之外引用一些项目.

Occasionally i need to reference some projects from outside the scope of the current .sln file.

例如,我的初始状态是:

For example, my initial state was this:

解决方案A

  • PROJ A
  • PROJ B

重构后,它看起来像这样:

After refactoring it would look like this:

解决方案A_NEW

  • PROJ A

解决方案B_NEW

  • PROJ B

我的问题是-是否可以向未在同一VS解决方案中定义的项目中添加 ProjectReference 节点? (就我而言,让 PROJ A 具有对 PROJ B 的项目引用).

My question is -- Is it possible to add a ProjectReference node to a project that is not defined in the same VS solution? (in my case, having PROJ A have a project reference to PROJ B).

还有可能吗?

我知道,仅通过手动编辑.csproj文件,在VS IDE中是不可能的.

I know that this is not possible from the VS IDE, only by editing the .csproj file manually.

推荐答案

您不能这样做. 项目参考包括所参考项目的标识GUID,该GUID保留在解决方案文件中,以便跟踪解决方案构建选项和依赖项.如果您尝试引用解决方案中没有的项目,Visual Studio将会抱怨.

You can't do this. A project reference includes an identifying GUID for the referenced project, which is maintained in the solution file in order to track solution build options and dependencies. If you try to reference a project that is not in the solution, Visual Studio will complain.

您当然可以向不在解决方案中的项目产生的程序集添加文件引用.

You can add a file reference to the assembly produced by a project that's not in the solution, of course.

更新:由于这已被否决,我将完善我的答案.

UPDATE: Since this got downvoted, I'll refine my answer.

尽管制作一个引用相同解决方案之外的另一个项目的项目文件在技术上是可行的,但Visual Studio不会帮助您轻松地做到这一点.这样做(我观察到)是个坏主意的一个很好的理由是,如果MSBuild决定构建引用的项目,则将忽略正在构建的任何解决方案配置和平台(引用的项目)-默认配置而是将使用该引用项目文件中指定的平台.因此,您最终可能会在不同的文件夹中混合使用二进制类型.

Though it's technically possible to craft a project file that references another project outside the same solution, Visual Studio won't help you to do it easily. One very good reason why it's a bad idea to do this (that I've observed) is that whatever Solution Configuration and Platform you're building (the referencing project) will be ignored if MSBuild decides to build the referenced project - the default Configuration and Platform specified in that referenced project file will be used instead. Thus you may end up with a mixture of binary types in different folders.

这篇关于将ProjectReference添加到不在同一解决方案中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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