【问题标题】:Fakes stopped working after installing Visual Studio 2015安装 Visual Studio 2015 后,Fake 停止工作
【发布时间】:2016-01-03 09:36:40
【问题描述】:

我已经安装了 Visual Studio 2015 作为试用版,从那时起,我使用 fakes 的单元测试将不再编译,甚至在 VS 2013 上也无法编译。单元测试项目的目标是 .net 4.5。

Msdn 建议更改目标框架版本。如果我将目标框架更改为 4.6,错误就消失了,但我无法将我的项目更新到 .net 4.6,因为每个开发人员都必须立即更新。

我得到的错误:

无法解析主要参考“mscorlib.4.0.0.0.Fakes” 因为它是针对“.NETFramework,Version=4.6 框架。这是比当前目标更高的版本 框架“.NETFramework,Version=4.5”。

我也尝试删除假货并重新创建它们,但它们没有构建,我收到如下错误:

类型或命名空间名称“EventDataAttribute”不存在于 命名空间'System.Diagnostics.Tracing'*;

有什么解决办法吗?

【问题讨论】:

  • 到目前为止,我的解决方案是删除所有假货并用 RhinoMocks 替换它们...

标签: .net visual-studio-2013 visual-studio-2015 microsoft-fakes


【解决方案1】:

您可能可以删除问题类。如果您的构建输出包含类似

的语句
warning CS0115: 'System.Security.Cryptography.X509Certificates.Fakes.StubX509Certificate2.Dispose(bool)': no suitable method found to override 
warning CS0234: The type or namespace name 'EventDataAttribute' does not exist in the namespace 'System.Diagnostics.Tracing'

然后可以从 mscorlib.fakes 或 System.fakes 文件中删除它

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="mscorlib" Version="4.0.0.0"/>
  <StubGeneration>
    <Remove FullName="System.Diagnostics.Tracing"/>
    <Remove FullName="System.Text.Encoding"/>
    <Remove FullName="System.Security.Cryptography" />
  </StubGeneration>
</Fakes>

现在,它可能比这更细微。为了让它工作,我需要将单元测试项目定位到 4.6 以第一次生成 mscorlib.4.0.0.0.Fakes .dll。然后我可以将它重新定位到 4.5.1。但是,使用配置可能值得您花一些时间,因为我能够解决类似的问题。

这是一个Microsoft problem 报告,这是我找到解决方法的地方。

【讨论】:

  • 答案末尾的链接已过时:“Microsoft Connect 已停用”
【解决方案2】:

我不得不提一下,除了 doobop 发布的对我有用的解决方案之外,还需要以下几行:

<Remove FullName="System.FormattableString" />
<Remove FullName="System.IO" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 2017-12-18
    • 2021-03-16
    • 1970-01-01
    • 2023-03-22
    • 2023-03-06
    相关资源
    最近更新 更多