2

我正在寻找一种使用相对文件路径来定义程序集分辨率值的方法。

我通过定义和引用 Microsoft文档推荐的环境变量来解决这个问题。正如您从下面的代码片段中看到的那样,我已经定义了一个环境变量“test”并在 MSTest 适配器部分引用它。使用 VS 编译和运行测试会产生关于缺少引用依赖项的错误。

我已验证通过将“测试”值设置为等于硬编码目录路径来解决此问题。除了代码片段中设置的值之外,我还尝试了以下“test”的值定义,但均未成功:

  • $(OutDir)............\一些\路径\
  • $(MSBuildProjectDirectory)........\some\path\
<RunConfiguration>
      <MaxCpuCount>1</MaxCpuCount>
      <!-- Path relative to directory that contains .runsettings file-->
      <ResultsDirectory>.\TestResults</ResultsDirectory>

      <!-- x86 or x64 -->
      <!-- You can also change it from the Test menu; choose "Processor Architecture for AnyCPU Projects" -->
      <TargetPlatform>x86</TargetPlatform>

      <!-- Framework35 | [Framework40] | Framework45 -->
      <TargetFrameworkVersion>Framework40</TargetFrameworkVersion>

      <!-- Path to Test Adapters -->
      <TestAdaptersPaths>%SystemDrive%\Temp\foo;%SystemDrive%\Temp\bar</TestAdaptersPaths>

      <!-- TestSessionTimeout was introduced in Visual Studio 2017 version 15.5 -->
      <!-- Specify timeout in milliseconds. A valid value should be greater than 0 -->
      <TestSessionTimeout>10000</TestSessionTimeout>

      <!-- true or false -->
      <!-- Value that specifies the exit code when no tests are discovered -->
      <TreatNoTestsAsError>true</TreatNoTestsAsError>
      
      <EnvironmentVariables>
         <!-- List of environment variables we want to set-->
         <test>.\..\..\..\..\some\path\</test>
      </EnvironmentVariables>
   </RunConfiguration>

   <MSTest>
      <MapInconclusiveToFailed>True</MapInconclusiveToFailed>
      <CaptureTraceOutput>false</CaptureTraceOutput>
      <DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
      <DeploymentEnabled>False</DeploymentEnabled>
      <AssemblyResolution>
         <Directory path="%test%" includeSubDirectories="false"/>
      </AssemblyResolution>
   </MSTest>

如何获得相对路径?

4

0 回答 0