添加到同一解决方案中的一个项目的项目引用在另一个解决方案中似乎已损坏
我有几个解决方案。
在第一个解决方案中,我有很多项目。名为“A”的项目之一具有同一解决方案的另一个项目“B”的项目引用。
在第二个解决方案中,添加了项目“A”,但未添加项目“B”。
两个解决方案均已成功构建。
但是,在第二个解决方案中,参考 添加到项目A中的B,出现 坏了。
为什么?
现在,在第一个解决方案中,我不是将 B 的项目引用添加到 A 中,而是简单地将 B 的 DLL 的“文件引用”(复制到为所有项目创建的公共输出目录中复制)到 A 中。现在引用似乎已损坏在解决方案和第一个解决方案中均未成功构建。
我可以知道当我 有这样的场景吗?
编辑:我查看了项目A的项目文件,发现 Path (
属性)对于B的项目引用,是相对路径。 (如“..\B\B.csproj”)。 我想这就是为什么此引用在第二个程序集中出现损坏的原因,因为程序集 B 不是第二个解决方案的一部分,并且显然“B.csproj”在使用相对路径解析引用时不可用。
I have couple of solutions.
In the first solution I have many projects. One of the project named 'A' has a project reference of another project 'B' of the same solution.
In second solution, the project 'A' is added but not the project 'B'.
Both the solutions build successfully.
However, in second solution, reference
of B added in the project A, appears
broken.Why?
Now, in first solution, instead of adding Project reference of B into A, i simply add a 'file reference' of B's DLL (which is copied at the common output directory created for all the projects) into A. Now the reference appears broken in both the solution and first solution does not build successfully.
May I know what should I do when I
have such a scenario?
EDIT: I looked at the project file of project A and found that the Path (<ProjectReference Include = "..\B\B.csproj" />
attribute) for project reference of B, is the relative path. (like "..\B\B.csproj").
I guess this is the reason why this reference appears broken in second assembly because the assembly B is not part of the second solution and obviously 'B.csproj' is not available while resolving reference using the relative path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种方法可以引用项目的输出:
第一种情况是在您没有创建的项目时使用的该程序集作为您的解决方案的一部分。通常,这用于引用来自第 3 方的程序集,或者不经常更改的程序集。
第二种情况要求您引用的项目存在于解决方案中。
听起来您已经混合了引用,创建了对不属于解决方案一部分的项目的项目引用。这是行不通的。
There's two ways to reference the output of a project:
The first scenario is used when you don't have the project that creates that assembly as part of your solution. Typically this is used to reference assemblies that come from 3rd party, or that doesn't change all that often.
The second scenario require the project you reference to be present in the solution.
It sounds like you've mixed the references, creating a project reference to a project that isn't part of the solution. This doesn't work.
在第一个解决方案中,您将“B”作为“项目参考”添加到项目“A”中。现在,当您将项目“A”添加到第二个解决方案时,它在第二个解决方案中查找“项目 B”(因为它是“项目引用”),显然找不到它,因此它显示了警告。
然而,在运行时,项目“A”知道在哪里可以找到项目 B 的输出,因此引用将被解析,并且在运行时不会出现问题。 (这就是两个解决方案都成功构建的原因)
对于第二种情况(直接添加对 B 的 DLL 的引用),它对我来说工作得很好。当您说“添加文件引用”时,我假设您的意思是直接添加对 DLL 的引用(右键单击“引用”->“添加引用”->“程序集”->“浏览”->“B.dll”),或者还有其他我不知道的方法吗? :
希望这有帮助:)
In the First solution, you added "B" as a "Project Reference" to project "A". Now, when you added project "A" to the second solution, it looked for "project B" in the second solution (since it's a "Project Reference"), it couldn't find it, obviously, so it showed a warning.
In runtime, however, project "A" knows where to find project B's output, so the references will be resoulved and you shouldn't have a problem at runtime. (and that's why both solutions build successfully)
For the second scenario (adding a reference to B's DLL directly), it worked just fine for me. When you say "add a file reference", I'm assuming you mean adding a reference to the DLL directly (right-click on References->Add Reference->Assemblies->browse->B.dll), or is there another way that i don't know about? :s
Hope this helped :)