gpt4 book ai didi

Fakes assembly is not generating(未生成假冒程序集)

转载 作者:bug小助手 更新时间:2023-10-25 17:26:28 38 4
gpt4 key购买 nike



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/ .fakes添加到我的项目中,并构建了该项目。有大量的警告,但没有错误,构建成功完成。但它不会添加对生成的.Fake程序集的任何引用。



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程序集不可见。程序集中实际上只有一个我想填充的类,没有任何我想要存根的类。因此,我编辑了.fakes文件:



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


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.

我清理并重新生成了该项目,但仍然收到大量警告,没有任何错误,说明它无法清除或填充我已排除在.fakes文件中的类,并且仍未生成.Fake程序集。



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.

实际上,我如何阻止它尝试创建存根,而只为特定名称空间中的类创建填补?来自http://msdn.microsoft.com/en-us/library/hh708916.aspx的信息显然是不正确的。



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?

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


更多回答

Note that there are some difficulties if classes are sealed or are certain classes from mscorlib. These may not be possible to Fake. Currently, we don't have enough information to explain the cause of your issue.

请注意,如果类是密封的,或者是来自mscallib的某些类,则会有一些困难。这些可能是不可能伪造的。目前,我们没有足够的信息来解释您问题的原因。

There are some sealed classes in the assembly, but I am not interested in those. The class I am trying to shim is public and not sealed. I am trying to modify the .fakes file to exclude those sealed classes. It just doesn't seem to care what I put in the .fakes file.

程序集中有一些密封的类,但我对这些不感兴趣。我试图填补的类是公开的,而不是密封的。我正在尝试修改.fakes文件以排除那些密封的类。它似乎并不关心我在.fakes文件中放了什么。

@Nick did u find your answer? I have the exact same problem!

@尼克,你找到答案了吗?我也有同样的问题!

@Elhamabbasi my problem was just that my .fakes file did not match the schema. I had <StubGeneration> and <ShimGeneration> as child elements of the <Assembly> element but they are not supposed to be children, they are supposed to be siblings and come after the <Assembly>

@Elhamabbasi我的问题只是我的.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:

我发现了我的问题所在。我认为StubGeneration和ShimGeneration应该是Assembly的子元素,但它们不是。它们应该是fake的子元素,也是Assembly的兄弟。将我的.fakes文件更改为以下文件后,它可以工作:



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


I had this issue for a long time. I found that none of my fellow team members had the same issue when compiling. The difference turned out to be that I was running Visual Studio 2022 Professional while they were running Visual Studio 2022 Enterprise. Once I uninstalled Professional and then Installed Enterprise the issue went away.

我有这个问题很长一段时间了。我发现我的团队成员在编译时都没有同样的问题。不同之处在于,我运行的是Visual Studio 2022专业版,而他们运行的是Visual Studio 2022企业版。一旦我卸载了专业版,然后安装了企业版,这个问题就消失了。


更多回答

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com