Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

c# - Specify Relative File Paths with RunSettings File

I am seeking a way to define assembly resolution values using relative file paths.

I am approaching this by defining and referencing an environment variable as recommend by the Microsoft documentation. As you can see from the code snippet below, I have defined an environment variable 'test' and am referencing it in the MSTest Adapter section. Compiling and running the tests with VS produces an error regarding missing reference dependencies.

I have verified this issue is resolved by setting the 'test' value to equal the hard coded directory path. In addition to the value set in the code snippet, I have also tried the following value definitions for 'test' without success:

  • $(OutDir)............somepath
  • $(MSBuildProjectDirectory)........somepath
<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%Tempfoo;%SystemDrive%Tempar</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>.........somepath</test>
      </EnvironmentVariables>
   </RunConfiguration>

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

How can I get the paths to be relative?

question from:https://stackoverflow.com/questions/65923863/specify-relative-file-paths-with-runsettings-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...