After installing .NET 4.5, previous Unit-Test project fails to build

不打扰是莪最后的温柔 提交于 2019-12-08 14:36:08

问题


I have a .NET 4.0 WPF solution that includes a Unit Test project which tests the different commands used in the viewmodels. Everything was fine. Then I installed .NET framework 4.5 and then VS2012, and started getting error messages like -

XYZProject.UsersViewModel_Accessor.AddUserToAccountsCommand' is not supported by the language

Before installing VS2012 the UnitTestFramework.dll was referenced from -

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\

which was changed to be referenced from -

C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v4.0

So it was taking the reference from within VS2012, and I manually restored that reference. But no luck.

The AddUserToAccountsCommand is an ICommand object which resides in PresentationCore.dll in .NET 4.0, but in System.dll in .NET 4.5. So I checked those references too, and they seems OK as they were previously.

The error message displays only where the test target is created as Accessors like UsersViewModel_Accessor, means the following code generates error-

UsersViewModel_Accessor target = new UsersViewModel_Accessor();
Assert.IsTrue(target.AddUserToAccountsCommand.CanExecute(null), "Failed to perform can exetuce of add user command");
target.AddUserToAccountsCommand.Execute(null);  

But if the test target is created using the viewmodel type directly as follows -

UsersViewModel target = new UsersViewModel();
Assert.IsTrue(target.AddUserToAccountsCommand.CanExecute(null), "Failed to perform can exetuce of add user command");
target.AddUserToAccountsCommand.Execute(null);  

no error occurs and project builds successfully. So, can anyone share any thought?

EDIT : After started getting the error I also installed VS2010 SP1. Still no luck.

EDIT2 : On the same machine I need to use VS2012 too for other projects, so it won't be a solution to uninstall .NET 4.5 or VS2012. Just to check, I took the solution on a different machine and this time installed .NET 4.5 only, not the VS2012, and tried to build the project. Same story. SO, the issue is NOT related to VS2012, it's something that's conflicting between .NET 4.0 and .NET 4.5 framework. To Reflect this I'm changing the Title of the question.

来源:https://stackoverflow.com/questions/14605765/after-installing-net-4-5-previous-unit-test-project-fails-to-build

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