vstest icon indicating copy to clipboard operation
vstest copied to clipboard

WorkingDirectory coming incorrectly for .NET Core and .NetFramework

Open saikrishnav opened this issue 9 years ago • 11 comments

Description

With .Net Core 1.0, Working DIrectory is IDE folder whereas with .Net framework, it is System32 folder.

Steps to reproduce

File -> New -> Test -> Unit test project:

When test app targets only .NET Core 1.0:

Directory.GetCurrentDirectory() = C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE

When test app targets both .NET core 1.0 and .NET Framwork: (netcoreapp1.0;net451)

Directory.GetCurrentDirectory() = C:\Windows\system32

Expected behavior

Expected Working Directory should be the directory where the test binary is. Since TestResults folder, or TRX files or Code Coverage files are generated relative to working directory, this is required to be "Test binary" directory. Also, Compat.

Actual behavior

Actual is "system32" or "IDE" folder

saikrishnav avatar Jan 03 '17 06:01 saikrishnav

Related issues https://github.com/dotnet/cli/issues/4708. https://github.com/dotnet/cli/issues/4067

pvlakshm avatar Jan 05 '17 10:01 pvlakshm

Commit : https://github.com/Microsoft/vstest/commit/b554ca73e2cc87b8ea952ad915e7ec253bb73796

singhsarab avatar Jan 23 '17 04:01 singhsarab

I am seeing same problem.

test host used is: C:\Users\Darrell\.nuget\packages\microsoft.testplatform.testhost\15.0.0-preview-20170125-04\lib\netstandard1.5\testhost.dll

Directory.GetCurrentDirectory() is: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE

I am using xunit 2.2.0 and xunit.runner.visualstudio 2.2.0

dazinator avatar Mar 03 '17 17:03 dazinator

@dazinator Can you please try Microsoft.NET.Test.Sdk: 15.0.0. It should work for run scenarios, For debug scenario, .Net Core project WorkingDirectory comes as "C:\Windows\System32" for which bug is tracking for VS 15.1.

smadala avatar Mar 09 '17 13:03 smadala

@smadala i tested out Microsoft.NET.Test.Sdk: 15.0.0 and experienced the same issue. On running units tests from the MS Visual Studio 17 gui Directory.GetCurrentDirectory() is still C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE. When i use the cmdline tool the current directory is resolved correctly.

kdrblkbs avatar Mar 13 '17 13:03 kdrblkbs

@kdrblkbs

  • What version of VS are you using? Please use the latest Visual Studio RTM.
  • What dotnet framework does your project target?
  • What test framework are you using ?
  • By commandline tool, you mean dotnet test ?

singhsarab avatar Mar 13 '17 14:03 singhsarab

hello @singhsarab i am using MS Visual Studio Enterprise 2017 15.0.0-RTW+ 26228.4. The framework target of my test project is .NETCoreApp 1.0. I am using xunit 2.2.0 and xunit.runner.visualstudio 2.2.0, too. and the final answer is yes. regards

kdrblkbs avatar Mar 13 '17 15:03 kdrblkbs

This is interesting, as I tested this scenario and it works fine.

Can you please try the following commandline "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" pathToTestDll /framework:".NetCoreApp,Version=1.0"

singhsarab avatar Mar 13 '17 17:03 singhsarab

@singhsarab its working now. i guess i was relying on the debug mode to check the result of GetCurrentDirectory() conveniently. If it is relevant in my case it is still C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE and not C:\Windows\System32. thanks and regards

kdrblkbs avatar Mar 14 '17 10:03 kdrblkbs

In VS 2017 release, It seems that Directory.GetCurrentDirectory() returns C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE when debugging tests, but otherwise returns the test project's debug directory, aka {project_path}\bin\Debug.

Is this intended? Because it doesn't look like it's intended.

cwharris avatar Mar 17 '17 01:03 cwharris

@cwharris Yes, you are right,It is a bug, has been fixed, fix will be available VS 2017 update 1.

smadala avatar Mar 17 '17 05:03 smadala