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