2017-03-08 7 views
2

내 XUnit 2.2는 명령 행에서 dotnet test으로 실행하면 모든 통과를 테스트합니다. Visual Studio 2017의 테스트 탐색기에서 실행하면 어셈블리 바인딩 오류로 인해 일부 테스트가 실패합니다.유닛 테스트는 "dotnet test"로 통과하지만 Visual Studio 2017에서 실행하면 실패합니다. 테스트 탐색기

내 테스트 프로젝트는 .Net 4.6.2를 대상으로하며 .Net 4.6.2를 타겟팅하는 ASP.Net Core 1.1 응용 프로그램을 참조합니다. 단위 테스트는 .NET Core 1.1 릴리스 도구 및 Visual Studio 2017로 업그레이드하기 전에 VS 2015에서 올바르게 작동했습니다.

테스트 프로젝트에 대해 app.config 파일을 만들고 필요한 모든 바인딩 리디렉션을 시행 착오를 통해. 나는 확실하지 않다 나는 이것을해야만한다.

dotnet test을 사용할 때 런타임은 새로운 어셈블리 버전을 불만없이 사용합니다. Visual Studio에서 실행할 때 리디렉션이 필요합니다.

테스트를 실행하는 두 가지 방법간에 어셈블리 바인딩 동작이 다른 이유는 무엇입니까?

샘플 어셈블리 바인딩 오류 :

The operation failed. 
Bind result: hr = 0x80131040. No description available. 

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll 
Running under executable C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe 
--- A detailed error log follows. 

=== Pre-bind state information === 
LOG: DisplayName = Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 
(Fully-specified) 
LOG: Appbase = file:///C:/xx/xx/xx.Tests/bin/Debug/net462 
LOG: Initial PrivatePath = NULL 
LOG: Dynamic Base = NULL 
LOG: Cache Base = C:\Users\xxxxx\AppData\Local\Temp\a1ec4d3c-04ff-4fa0-9e56-129e799dd870 
LOG: AppName = a1ec4d3c-04ff-4fa0-9e56-129e799dd870 
Calling assembly : Serilog.Settings.Configuration, Version=2.2.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10. 
=== 
LOG: This bind starts in default load context. 
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe.Config 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. 
LOG: Post-policy reference: Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 
LOG: GAC Lookup was unsuccessful. 
LOG: Attempting download of new URL file:///C:/xx/xx/xx.Tests/bin/Debug/net462/Microsoft.Extensions.Configuration.Abstractions.DLL. 
LOG: Assembly download was successful. Attempting setup of file: C:\xx\xx\xx.Tests\bin\Debug\net462\Microsoft.Extensions.Configuration.Abstractions.dll 
LOG: Entering download cache setup phase. 
LOG: Assembly Name is: Microsoft.Extensions.Configuration.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 
WRN: Comparing the assembly name resulted in the mismatch: Minor Version 
ERR: The assembly reference did not match the assembly definition found. 
ERR: Setup failed with hr = 0x80131040. 
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

그리고 리디렉션을 해결하는 데 필요한 :

<dependentAssembly> 
     <assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.1.1.0" />" 
</dependentAssembly> 
+0

repro 프로젝트를 공유 할 수 있습니까? 또한 xunit net core 테스트 프로젝트에 새 테스트 템플릿을 사용하지 않는 것 같습니다. 그걸 사용해 볼 수 있니? – Sushil

답변

1

그것은이 문제는 해결 방법은 추가하는 것입니다 https://github.com/Microsoft/vstest/issues/428

에서 추적되고 밝혀 테스트 프로젝트의 csproj 파일에 다음 두 항목 :

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>  
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> 

이렇게하면 바인딩 리디렉션을 수동으로 추가 할 필요가 없습니다.