在 Visual Studio 2015 中破解的假货 [英] Fakes Broken in Visual Studio 2015
问题描述
我有 Visual Studio 2015 Enterprise 并发现我几乎无法编译我们现有的任何 2013 项目.进一步调查显示,Visual Studio 2015 无法为 Visual Studio 2013 中的正常类型生成假冒产品.
I have Visual Studio 2015 Enterprise and discovered that I cannot compile almost any of our existing 2013 projects. Further investigation reveals that Visual Studio 2015 isn't able to generate fakes for types that were fine in 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>
- 然后编辑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>
编译项目.
Compile the project.
这会在 mscorlib.4.0.0.0.Fakes.messages 文件(在 FakesAssemblies 文件夹中生成)中生成以下错误消息:
This generates the following error messages in mscorlib.4.0.0.0.Fakes.messages file (generated in the FakesAssemblies folder):
警告:编译失败,没有代码契约重试
warning : compilation failed, retrying without Code Contracts
以及输出窗口中的以下错误消息:
And the following error messages in the output window:
c: empUnitTestProject1UnitTestProject1f.cs(955,13):错误 CS0311:类型System.Collections.Concurrent.ConcurrentDictionary"不能用作泛型类型或方法中的类型参数TShimmed"'ShimRuntime.Bind(TShim, TBound)'.没有从System.Collections.Concurrent.ConcurrentDictionary"到System.Collections.Generic.IReadOnlyCollection>"的隐式引用转换.[c: empUnitTestProject1UnitTestProject1objDebugFakesmf.csproj]
c: empUnitTestProject1UnitTestProject1f.cs(955,13): error CS0311: The type 'System.Collections.Concurrent.ConcurrentDictionary' cannot be used as type parameter 'TShimmed' in the generic type or method 'ShimRuntime.Bind(TShim, TBound)'. There is no implicit reference conversion from 'System.Collections.Concurrent.ConcurrentDictionary' to 'System.Collections.Generic.IReadOnlyCollection>'. [c: empUnitTestProject1UnitTestProject1objDebugFakesmf.csproj]
c: empUnitTestProject1UnitTestProject1f.cs(979,13):错误 CS0311:类型System.Collections.Concurrent.ConcurrentDictionary"不能用作泛型类型或方法中的类型参数TShimmed"'ShimRuntime.Bind(TShim, TBound)'.没有从System.Collections.Concurrent.ConcurrentDictionary"到System.Collections.Generic.IReadOnlyDictionary"的隐式引用转换.[c: empUnitTestProject1UnitTestProject1objDebugFakesmf.csproj]
c: empUnitTestProject1UnitTestProject1f.cs(979,13): error CS0311: The type 'System.Collections.Concurrent.ConcurrentDictionary' cannot be used as type parameter 'TShimmed' in the generic type or method 'ShimRuntime.Bind(TShim, TBound)'. There is no implicit reference conversion from 'System.Collections.Concurrent.ConcurrentDictionary' to 'System.Collections.Generic.IReadOnlyDictionary'. [c: empUnitTestProject1UnitTestProject1objDebugFakesmf.csproj]
GENERATEFAKES : 错误:项目编译失败,退出代码为 1
GENERATEFAKES : error : project compilation failed with exit code 1
摆弄 mscorlib.fakes 设置似乎无济于事.例如,TypeName、FullName 和 Namespace 属性的各种排列产生相同的编译失败,退出代码 1".
No amount of fiddling with mscorlib.fakes settings appears to help. For example various permutations of the TypeName, FullName and Namespace attributes yield the same "compilation failed with exit code 1".
禁用代码契约只会破坏它更多:
Disabling code contracts just breaks it more:
警告命名空间http://schemas.microsoft.com/fakes/2011/' 在命名空间http://schemas.microsoft.com/fakes/2011/'.UnitTestProject1 c: empUnitTestProject1UnitTestProject1Fakesmscorlib.fakes 4
Warning The element 'Fakes' in namespace 'http://schemas.microsoft.com/fakes/2011/' has invalid child element 'StubGeneration' in namespace 'http://schemas.microsoft.com/fakes/2011/'. UnitTestProject1 c: empUnitTestProject1UnitTestProject1Fakesmscorlib.fakes 4
如果您能帮助理解如何解决/解决此问题,我们将不胜感激.
Any help understanding how to fix/work around this problem would be very much appreciated.
推荐答案
如果您使用的是 Visual Studio 2015 Enterprise.请删除旧的 Xrm dll 和添加新的 CRM 2016 SDK Xrm Dll 构建项目还将 .Net Framework 更改为最新版本.
If you are doing with Visual Studio 2015 Enterprize.kindly remove Old Xrm dll's and Add new CRM 2016 SDK Xrm Dll's Build the project also change the .Net Framework to latest.
构建项目后,我们将获得 Generate System Fakes Assemblymscorlib 和 system.Fakes 只需删除这行
<Add FullName="ConcurrentDictionary"/>
在这两个文件上并构建项目After build the project Generate System Fakes Assembly we will get mscorlib and system.Fakesjust remove this line
<Add FullName="ConcurrentDictionary"/>
on both files and build the project这篇关于在 Visual Studio 2015 中破解的假货的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!