在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.
请考虑以下步骤进行复制:
Consider the following steps to reproduce:
- 创建一个针对.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:\ temp \ UnitTestProject1 \ UnitTestProject1 \ f.cs(955,13):错误CS0311:类型'System.Collections.Concurrent.ConcurrentDictionary'不能用作通用类型或方法中的类型参数'TShimmed' 'ShimRuntime.Bind(TShim,TBound)'.没有从"System.Collections.Concurrent.ConcurrentDictionary"到"System.Collections.Generic.IReadOnlyCollection>"的隐式引用转换. [c:\ temp \ UnitTestProject1 \ UnitTestProject1 \ obj \ Debug \ Fakes \ m \ f.csproj]
c:\temp\UnitTestProject1\UnitTestProject1\f.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:\temp\UnitTestProject1\UnitTestProject1\obj\Debug\Fakes\m\f.csproj]
c:\ temp \ UnitTestProject1 \ UnitTestProject1 \ f.cs(979,13):错误CS0311:类型'System.Collections.Concurrent.ConcurrentDictionary'不能用作通用类型或方法中的类型参数'TShimmed' 'ShimRuntime.Bind(TShim,TBound)'.没有从"System.Collections.Concurrent.ConcurrentDictionary"到"System.Collections.Generic.IReadOnlyDictionary"的隐式引用转换. [c:\ temp \ UnitTestProject1 \ UnitTestProject1 \ obj \ Debug \ Fakes \ m \ f.csproj]
c:\temp\UnitTestProject1\UnitTestProject1\f.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:\temp\UnitTestProject1\UnitTestProject1\obj\Debug\Fakes\m\f.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:\ temp \ UnitTestProject1 \ UnitTestProject1 \ Fakes \ mscorlib.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:\temp\UnitTestProject1\UnitTestProject1\Fakes\mscorlib.fakes 4
非常感谢您了解如何解决/解决此问题.
Any help understanding how to fix/work around this problem would be very much appreciated.
推荐答案
-
如果您使用的是Visual Studio 2015,请Enterprize.kindly remove 旧的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 Assembly之后,我们将获得 mscorlib和system.只需在两个文件中删除此行
<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屋!
-