0

When I run tests in Visual Studio I have a test folder containing testdata. To reach these I use

File.ReadAllText(Path.Combine("testData", "input.html"));

But instead of looking in the project folder where the testdata is located C:\repos\myproject\testdata

Visual studio tries to find the file in

`C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\testData\input.html`

Which results in the following error:

`Message: System.IO.DirectoryNotFoundException : Could not find a part of the 
path 'C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Professional\Common7\IDE\testData\input.html'.`

Since we are several people working with the same project we need to use relative paths. Where can I change the relative path that VS is using? I'm using Visual Studio Professional 2017.

I have tried the first solution in

How to define relative paths in Visual Studio Project?

but both the solution and project property page is different in VS Pro 2017.

Images:

Solution properties

Project properties

ColdFire
  • 6,764
  • 6
  • 35
  • 51
Jesper Lundin
  • 168
  • 1
  • 8
  • is it a web app or desktop app? – Gaurang Dave Apr 11 '18 at 09:11
  • you can use System.IO.Path.Combine(Environment.CurrentDirectory, filepath); for getting relative path. – Gaurang Dave Apr 11 '18 at 09:12
  • Always use the full path of a file to avoid Environment.CurrentDirectory accidents like this. c:\foo\bar\baz.ext. Consider getting the c:\foo\bar part from Assembly.GetExecutingAssembly().Location – Hans Passant Apr 11 '18 at 09:16
  • If you're running your unit tests in Visual Studio, you might be able to use [`[DeploymentItem]`](https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute.aspx) – stuartd Apr 11 '18 at 09:51

0 Answers0