VS2010 SP1 unit tests targeting 3.5 framework fail if using private accessor

这一生的挚爱 提交于 2019-12-04 11:35:58

I ran into this problem as well. Visual Studio 2010 SP1 adds support for unit test projects based on .NET v3.5; previously unit tests were forced to use .NET4.

There is a Microsoft Connect bug on the subject but it was just filed the day I'm writing this answer so there is no meaningful response from Microsoft yet.

The workaround I chose was to manually generate the private accessor assembly using Visual Studio 2008 toolchain and add a manual reference to it from the unit test project.

The steps are:

1) Remove the autogenerated accessor from the unit test .csproj file:

<ItemGroup>
  <Shadow Include="Test References\Assembly.accessor" />
</ItemGroup>

2) Create the v3.5 compatible accessor assembly using Publicize VS2008:

"%VS90COMNTOOLS%vsvars32.bat"
publicize Assembly.dll

3) Copy the assembly to the source tree folder, e.g. under a folder Accessors:

copy Assembly_Accessor.dll ProjectDir\Accessors\Assembly_Accessors.dll

4) Add the accessor assembly as a reference to the unit test project using the Visual Studio interface:

Project -> Add Reference.. -> Browse...

5) Build your solution with Ctrl+Shift+B and run your tests.

You can now either check in the generated assembly or create it automatically in a pre-build event.

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