當在Visual Studio 2017年將SQL服務器單元測試項目的單元測試項目,我得到以下錯誤:錯誤的單元測試項目2017年
The reference "Microsoft.VisualStudio.QualityTools.UnitTestFramework,
Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL" could not be added to the project.
This wizard will continue to run, but the resulting project may not build properly.
該項目似乎構建細算賬,但所有SQL單元測試失敗,出現以下錯誤:
Test Name: SqlTest1
Test FullName: UnitTestProject1.SqlServerUnitTest1.SqlTest1
Test Source: c:\[path]\SqlServerUnitTest1.cs : line 34
Test Outcome: Failed
Test Duration: 0:00:00.0278356
Result StackTrace:
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
Result Message:
Unable to set TestContext property for the class
UnitTestProject1.SqlServerUnitTest1.
Error: System.ArgumentException: Object of type
'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation'
cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'..
[我已經解決了這個問題,並將下面的答案添加到我的解決方案中,我將其創建爲記錄其他人可能會覺得有用的解決方案。如果其他任何人遇到過這種情況,我仍會感興趣,並且可以從中找出原因]