简体   繁体   English

间接引用解决方案项目会导致“类型在未引用的程序集中定义”

[英]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忽略/覆盖BA的引用,而改用项目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必须在BB必须先于TA之前构建,否则BTA将引用A不同版本。 If B builds before A then it will reference an older version of A . 如果BA之前构建,则它将引用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: 我这样固定:

  • Changed 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。
  • Added 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.

相关问题 C#出现错误:在未引用的程序集中未定义类型“ Indirect.Class”。 必须添加对程序集“间接”的引用 - C# Getting Error: Type “Indirect.Class” Not Defined In an Assembly Not Referenced . Must Add a reference to assembly “Indirect” 该类型在未引用的程序集中定义 - The type is defined in an assembly that is not referenced 类型“ DbConnection”在未引用的程序集中定义。 我无法添加参考? - The type 'DbConnection' is defined in an assembly that is not referenced. I cannot add the reference? C#-引用类型&#39;ISomeInterface&#39;在未引用的程序集中定义 - C# - The reference type 'ISomeInterface' is defined in an assembly that is not referenced .Object类型是在.Net Core项目未引用的程序集中定义的 - The type 'Object' is defined in an assembly that is not referenced with .Net Core project 引用另一个程序集中的类型导致“在未引用的程序集中定义类型”Razor.Compile()中的错误 - Referencing type that is in another assembly causes “the type is defined in an assembly that is not referenced” error in Razor.Compile() 类型“HttpResponseMessage”是在未引用的程序集中定义的 - The type 'HttpResponseMessage' is defined in an assembly that is not referenced 类型“IEnumerable&lt;&gt;”是在未引用的程序集中定义的 - The type 'IEnumerable<>' is defined in an assembly that is not referenced &#39;Nullable&lt;&gt;&#39; 类型在未引用的程序集中定义 - The type 'Nullable<>' is defined in an assembly that is not referenced 类型“ MailAddress”在未引用的程序集中定义 - The type 'MailAddress' is defined in an assembly that is not referenced
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM