开发者

Project Reference added to one of the projects in the same solution appears broken in another solution

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.


There's two ways to reference the output of a project:

  1. Referencing the compiled assembly (the .dll file)
  2. Referencing the project itself, implying that you require the output from compiling it

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.


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜