在Visual Studio 2015中伪造



我有Visual Studio 2015 Enterprise,发现我无法编译几乎任何现有的2013项目。进一步的调查显示,Visual Studio 2015无法生成在Visual Studio 2013中可以正常使用的类型。

考虑以下步骤来复制:

  • 创建一个针对。net 4.5的单元测试项目
  • 右键单击"System",选择"Add Fakes Assembly"
  • 为了消除本例中的噪声,编辑后面的"System."假货"文件:
<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>
  • 然后编辑"mscorlib. exe"。"伪造"文件。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>
  • 编译项目。

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

警告:编译失败,重试没有代码契约

和以下错误消息在输出窗口:

c:tempUnitTestProject1UnitTestProject1f.cs(95,13):错误CS0311:类型'System.Collections.Concurrent. error。ConcurrentDictionary'不能用作泛型类型或方法'ShimRuntime '中的类型参数'TShimmed'。Bind (TShim TBound)"。没有从"System.Collections.Concurrent"进行的隐式引用转换。ConcurrentDictionary'到'System.Collections.Generic.IReadOnlyCollection>'。(c: temp UnitTestProject1 UnitTestProject1 obj 调试假货 m f.csproj]

c:tempUnitTestProject1UnitTestProject1f.cs(979,13):错误CS0311:类型'System.Collections.Concurrent. error。ConcurrentDictionary'不能用作泛型类型或方法'ShimRuntime '中的类型参数'TShimmed'。Bind (TShim TBound)"。没有从"System.Collections.Concurrent"进行的隐式引用转换。ConcurrentDictionary'到'System.Collections.Generic.IReadOnlyDictionary'。(c: temp UnitTestProject1 UnitTestProject1 obj 调试假货 m f.csproj]

GENERATEFAKES: error:项目编译失败,退出码1

不要再摆弄mscorlib了。Fakes Settings似乎有所帮助。例如,TypeName, FullName和Namespace属性的各种排列都会产生相同的"编译失败,退出代码为1"。

禁用代码契约只会破坏它:

警告命名空间'http://schemas.microsoft.com/fakes/2011/'中的元素'Fakes'在命名空间'http://schemas.microsoft.com/fakes/2011/'中有无效的子元素'StubGeneration'。UnitTestProject1 c: temp UnitTestProject1 UnitTestProject1 假货 mscorlib。假货4

任何帮助理解如何修复/工作围绕这个问题将非常感激。

  1. 如果您正在使用Visual Studio 2015 enterprise。请删除旧的Xrm dll和添加新的CRM 2016 SDK Xrm dll的构建项目

  2. 构建项目生成系统假组装后,我们将得到Mscorlib和system。Fakesjust删除这行<Add FullName="ConcurrentDictionary"/>在两个文件和构建项目

最新更新