使用 RunSettings 文件指定相对文件路径

yea*_*ine 5 .net c# runsettings

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

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

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

  • $(OutDir)............\一些\路径\
  • $(MSBuildProjectDirectory)........\一些\路径\
<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>
Run Code Online (Sandbox Code Playgroud)

如何使路径成为相对路径?