在Visual Studio 2015中打破假货

42v*_*ons 6 .net-4.5 microsoft-fakes visual-studio-2015

我有Visual Studio 2015 Enterprise,发现我几乎无法编译任何现有的2013项目.进一步调查显示,Visual Studio 2015无法为Visual Studio 2013中的类型生成假货.

请考虑以下步骤来重现:

  • 创建面向.NET 4.5的单元测试项目
  • 右键单击引用选项卡中的"系统",然后选择"添加假装配"
  • 要消除此示例中的噪声,请编辑后续的"System.fakes"文件:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="System" Version="4.0.0.0"/>
  <StubGeneration>
    <Clear/>
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
  </ShimGeneration>  
</Fakes>
Run Code Online (Sandbox Code Playgroud)
  • 然后编辑"mscorlib.fakes"文件以填充ConcurrentDictionary <TKey,TValue>:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="mscorlib" Version="4.0.0.0"/>
  <StubGeneration>
    <Clear/>
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
    <Add FullName="ConcurrentDictionary"/>
  </ShimGeneration>
</Fakes>
Run Code Online (Sandbox Code Playgroud)
  • 编译项目.

  • 这会在mscorlib.4.0.0.0.Fakes.messages文件中生成以下错误消息(在FakesAssemblies文件夹中生成):

警告:编译失败,重试没有代码合同

并在输出窗口中显示以下错误消息:

c:\ temp\UnitTestProject1\UnitTestProject1\f.cs(955,13):错误CS0311:类型'System.Collections.Concurrent.ConcurrentDictionary'不能在泛型类型或方法'ShimRuntime中用作类型参数'TShimmed'. Bind(TShim,TBound)'.没有从'System.Collections.Concurrent.ConcurrentDictionary'到'System.Collections.Generic.IReadOnlyCollection>'的隐式引用转换.[C:\ TEMP\UnitTestProject1\UnitTestProject1\OBJ \调试\伪造品\米\ f.csproj]

c:\ temp\UnitTestProject1\UnitTestProject1\f.cs(979,13):错误CS0311:类型'System.Collections.Concurrent.ConcurrentDictionary'不能在泛型类型或方法'ShimRuntime中用作类型参数'TShimmed'. Bind(TShim,TBound)'.没有从'System.Collections.Concurrent.ConcurrentDictionary'到'System.Collections.Generic.IReadOnlyDictionary'的隐式引用转换.[C:\ TEMP\UnitTestProject1\UnitTestProject1\OBJ \调试\伪造品\米\ f.csproj]

GENERATEFAKES:错误:项目编译失败,退出代码为1

没有任何摆弄mscorlib.fakes设置似乎有帮助.例如,TypeName,FullName和Namespace属性的各种排列产生相同的"编译失败并退出代码1".

禁用代码合同只会打破更多:

警告元素"正版正货"命名空间" http://schemas.microsoft.com/fakes/2011/具有无效的子元素命名空间"StubGeneration" http://schemas.microsoft.com/fakes/2011/ ".UnitTestProject1 c:\ temp\UnitTestProject1\UnitTestProject1\Fakes\mscorlib.fakes 4

任何帮助理解如何解决/解决这个问题将非常感激.

Sri*_*Hsk -1

  1. 如果您使用 Visual Studio 2015 Enterprize,请删除旧的 Xrm dll 并添加新的 CRM 2016 SDK Xrm Dll 构建项目,并将 .Net Framework 更改为最新版本。

  2. 构建项目Generate System Fakes Assembly后,我们将得到mscorlib和system.Fakes只需删除这 <Add FullName="ConcurrentDictionary"/>两个文件上的这一行并构建项目