假装配不生成 [英] Fakes assembly is not generating

查看:35
本文介绍了假装配不生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我需要做什么来生成假货.在我的测试项目中,我包含了对我想要伪造的程序集的引用.它将/Fakes/.fakes 添加到我的项目中并构建了该项目.有很多警告,但有 0 个错误并且构建成功完成.但它没有添加对生成的 .Fakes 程序集的任何引用.

I can't figure out what I need to do to generate Fakes. In my test project I included a reference to the assembly that I want to fake. It added /Fakes/<assembly name>.fakes to my project and it built the project. There were a ton of warnings, but there are 0 errors and the build completed successfully. But it is not adding any reference to the generated .Fakes assembly.

大多数警告是诸如无法为枚举生成存根或垫片之类的事情,或者某些私有类对 fakes 程序集不可见.程序集中实际上只有 1 个类要填充,而没有要存根的类.所以我编辑了 .fakes 文件:

Most of the warnings were things like cannot generate stubs or shims for an enum, or some private class is not visible to the fakes assembly. There's really only 1 class in the assembly that I want to Shim, and nothing that I want to Stub. So I edited the .fakes file:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"
       Diagnostic="true">
  <Assembly Name="[assembly name]">
    <StubGeneration>
      <Clear />
    </StubGeneration>
    <ShimGeneration>
      <Clear />
      <Add Namespace="[namespace that the 1 class I want to shim is in]" />
    </ShimGeneration>
  </Assembly>
</Fakes>

我清理并重建了该项目,但我仍然收到大量警告,并且没有错误,它不能存根或填充我在 .fakes 文件中排除的类,并且 .Fakes 程序集仍然没有正在生成.

I cleaned and rebuilt the project, and I am still getting tons of warnings, and no errors, that it can't stub or shim classes that I have excluded in the .fakes file, and the .Fakes assembly is still not getting generated.

我实际上如何阻止它尝试创建存根并仅为特定命名空间中的类创建垫片?信息来自 http://msdn.microsoft.com/en-us/library/hh708916.aspx 显然不正确.

How do I actually I stop it from trying to create stubs and only creating shims for classes that are in a specific namespace? The information from http://msdn.microsoft.com/en-us/library/hh708916.aspx is, apparently, not correct.

此外,我从 Assembly 元素中删除了 Version 属性,但我收到的警告仍然包含命名空间中的版本号.这是怎么回事?

Also, I removed the Version attribute from the Assembly element, but the warnings that I'm getting still include the version number in the namespace. What's up with that?

推荐答案

我发现了我的问题所在.我认为 StubGeneration 和 ShimGeneration 应该是 Assembly 的子元素,但它们不是.他们应该是 Fakes 的孩子,以及 Assembly 的兄弟姐妹.将我的 .fakes 文件更改为此后,它可以工作:

I found out what my problem was. I thought StubGeneration and ShimGeneration were supposed to be child elements of Assembly, but they aren't. They are supposed to be children of Fakes, and siblings of Assembly. After changing my .fakes file to this, it works:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"
       Diagnostic="true">
  <Assembly Name="[assembly name]" />
  <StubGeneration>
    <Clear />
  </StubGeneration>
  <ShimGeneration>
    <Clear />
    <Add Namespace="[namespace that the 1 class I want to shim is in]" />
  </ShimGeneration>
</Fakes>

这篇关于假装配不生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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