[英]Indirect reference to solution project causes “Type is defined in an assembly that is not referenced”
My solution contains project A
and test project TA
. 我的解决方案包含项目A
和测试项目TA
。 The test project references solution project A
and some DLL B
. 该试验项目参考解决方案项目A
和一些DLL B
。 The DLL B
references DLL generated by A
. DLL B
引用A
生成的DLL。 I have a type Foo
which is defined on A
and is tested by TA
. 我有一个Foo
类型,它在A
上定义,并由TA
测试。
When I tell to build TA
, VS2013 bombs me with: 当我告诉我建立TA
,VS2013用以下方法炸了我:
The type 'Foo' is defined in an assembly that is not referenced. You must add a reference to assembly 'A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. C:\mysolution\src\TA\TestFoo.cs 32 17 TA
However the type Foo
is defined on A
, which is on my solution!!! 但是类型Foo
是在A
上定义A
,这在我的解决方案中!!! Even the editor understands that!!! 甚至编辑也明白!!! Just the builder insists to use whatever is defined by B
. 只是建造者坚持使用B
定义的任何东西。
How can I tell VS to ignore/override the reference that B
has on A
, and use the output of my project A
instead? 如何告诉VS忽略/覆盖B
对A
的引用,而改用项目A
的输出?
Is there some assemblyBinding
or similar option that I can use to make the build work? 我可以使用一些assemblyBinding
或类似的选项来使构建工作吗?
So this is your dependency diagram if I understand you right: 因此,如果我理解正确,这就是您的依赖关系图:
TA --> B
| |
| V
---> A
It sounds like you have to explicitly set the build order. 听起来您必须显式设置构建顺序。 A
must build before B
and B
must build before TA
otherwise B
and TA
will be referencing different versions of A
. A
必须在B
和B
必须先于TA
之前构建,否则B
和TA
将引用A
不同版本。 If B
builds before A
then it will reference an older version of A
. 如果B
在A
之前构建,则它将引用A
的旧版本。
You can solve this by either making A
a project reference in B or explicitly setting the project dependencies for the solution in Visual Studio. 您可以通过在B中使A
成为项目引用或在Visual Studio中显式设置解决方案的项目依赖关系来解决此问题。
I fixed this way: 我这样固定:
TA.csproj
to not reference project A
in the same solution, but instead reference the same DLL that B
references. 将TA.csproj
更改为在相同的解决方案中不引用项目A
,而是引用B
引用的相同DLL。 App.config
to TA
, with an assemblyBinding
element that forces .NET to load the version of A
that I'm building in the solution, for the B
DLL. 为TA
添加了App.config
,其中带有assemblyBinding
元素,该元素强制.NET为B
DLL加载我在解决方案中构建的A
版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.