Fakes stopped working after installing Visual Studio 2015

旧巷老猫 提交于 2019-12-13 12:01:21

问题


I've installed Visual Studio 2015 as a try-out and since then my unit tests that use fakes won't compile anymore, not even on VS 2013. The unit test project targets .net 4.5.

Msdn suggest changing the target framework version. The error is gone if I change the targeted framework to 4.6 but I cannot update my project to .net 4.6 as every developer must update at once.

Error that I get:

The primary reference "mscorlib.4.0.0.0.Fakes" could not be resolved because it was built against the ".NETFramework,Version=4.6 fraemwork. This is a higher version than the currently targeted framework ".NETFramework,Version=4.5".

I've also tried to remove the fakes and recreate them but they do not build, I get errors like this:

The type or namespace name 'EventDataAttribute' does not exist in the namespace 'System.Diagnostics.Tracing'*;

Any fixes for this?


回答1:


You can probably remove the problem classes. If your build output has statements like

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'

Then it can be removed from mscorlib.fakes or System.fakes files

<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>

Now, it may be a bit more nuanced than that. In order to get it to work, I needed to target the Unit Test project to 4.6 to generate the mscorlib.4.0.0.0.Fakes .dll the first time. Then I could retarget it back down to 4.5.1. But, working with the config may be worth a bit of your time as I was able to work around a similar problem.

Here's a Microsoft problem report which is where I got the workaround.




回答2:


I have to mention that besides the solution posted by doobop, which worked for me, also the following lines were required:

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


来源:https://stackoverflow.com/questions/32970469/fakes-stopped-working-after-installing-visual-studio-2015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!