vstset.console.exe сбой разрешения сборки

#c# #visual-studio-2015 #mstest #runsettings #vstest.console.exe

#c# #visual-studio-2015 #mstest #настройки выполнения #vstest.console.exe

Вопрос:

У меня есть UnitTests.dll , на который Common.dll ссылается (оба построены с помощью VS2015).

У меня следующая структура каталогов:

 C:Test
    - UnitTests.dll
    - UnitTests.runsettings    
C:Bin
    - Common.dll
  

UnitTests.runsettings содержимое выглядит следующим образом:

 <?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <RunConfiguration>
        <TargetPlatform>x64</TargetPlatform>
    </RunConfiguration>
    <MSTest>
        <MapInconclusiveToFailed>True</MapInconclusiveToFailed>
        <CaptureTraceOutput>False</CaptureTraceOutput>
        <DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
        <DeploymentEnabled>False</DeploymentEnabled>
        <AssemblyResolution>
            <Directory Path="C:Bin" includeSubDirectories="true" />
        </AssemblyResolution>
    </MSTest>    
</RunSettings>
  

Я вызываю тесты:

 C:Test> vstest.console.exe UnitTests.dll /settings:UnitTests.runsettings /inIsolation
  

vstest.console.exe относится к C:Program Файлы (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe .


Я получаю следующую ошибку:

 Starting test execution, please wait... 
Failed   TestMethod1 
Error Message:
    Test method UnitTests.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Stack Trace:
    at UnitTests.UnitTest1.TestMethod1()
  

Подробнее, с включенным журналом слияния:

 Starting test execution, please wait... 
Failed   TestMethod1 
Error Message:
    Test method UnitTests.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
=== Pre-bind state information === 
LOG: DisplayName = Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  (Fully-specified)
LOG: Appbase = file:///C:/Test 
LOG: Initial PrivatePath = NULL 
Calling assembly : UnitTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
=== LOG: This bind starts in default load context. 
LOG: Using application configuration file: 
C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTestWindowvstest.executionengine.exe.Config 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config. 
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). 
LOG: Attempting download of new URL file:///C:/Test/Common.DLL. 
LOG: Attempting download of new URL file:///C:/Test/Common/Common.DLL. 
LOG: Attempting download of new URL file:///C:/Test/Common.EXE. 
LOG: Attempting download of new URL file:///C:/Test/Common/Common.EXE.

Stack Trace:
    at UnitTests.UnitTest1.TestMethod1()
  

Сталкиваюсь ли я с какой-то проблемой кэширования? Как убедить vstest.console.exe искать зависимости внутри C:Bin (как теоретически указано AssemblyResolution элементом)?


Обновить:

Отправлено как ошибка в MSFT при подключении (с повторными шагами — на вкладке СВЕДЕНИЙ внизу).

Существующие ограничения разрешения сборки и принудительное использование DeploymentItem атрибута вообще не масштабируются. Избыточные затраты на обслуживание (когда разработчики вынуждены вручную отслеживать, какие зависимости требуются для выполнения модульных тестов) создают трудности для тестов. Любые проблемы, возникающие в результате этого трения, очень сложно устранить.

Ответ №1:

Похоже, что документация Runsettings MSDN содержит опечатку в Directory элементе, атрибут path должен быть в нижнем регистре, чтобы работать. Ваш файл runsettings должен работать, если вы укажете

     <AssemblyResolution>
        <Directory path="C:Bin" includeSubDirectories="true" />
    </AssemblyResolution>
  

Ответ №2:

Установите атрибут DeploymentItemAttribute для всех необходимых файлов:

 [DeploymentItem("Common.dll")]
[DeploymentItem("Common2.dll")]
[TestMethod]
public void TestFoo()
{
    Bar();
}
  

Комментарии:

1. DeploymentItem атрибут работает, когда вы указываете полный путь и устанавливаете DeploymentEnabled значение элемента True в .runsettings файле. DeploymentItem атрибут не распознает переменные среды, несмотря на то, что это показано в примерах на MSDN. Разочаровывает также тот факт, что AssemblyResolution элемент больше не работает (как и ранее, в .testsettings file), но он все еще существует.

2. сообщите об этом как об ошибке в MS при подключении: connect.microsoft.com/VisualStudio/Feedback/

3. Я действительно собирался это сделать.

4. Отправлено: connect.microsoft.com/VisualStudio/Feedback/Details/3105814 (с шагами воспроизведения — на вкладке «СВЕДЕНИЯ» внизу).