From 4b01a785dfaaf9f82671ad4b53d161cf4c727f80 Mon Sep 17 00:00:00 2001 From: Steve MacLean Date: Wed, 10 Oct 2018 20:17:18 -0400 Subject: [PATCH] Add script to start Visual Studio (dotnet/core-setup#4614) * Add script to start Visual Studio Add script to properly set the environment variables to run tests within the Visual Studio IDE test explorer Add brief documentation Respond to feedback Commit migrated from https://github.com/dotnet/core-setup/commit/73ca15b61650d544d77eca0278ab3ea4ef6d8325 --- .../building/Running-Tests-In-VisualStudio-IDE.md | 19 +++++++++ src/installer/run.cmd | 2 +- src/installer/visual-studio-devenv.cmd | 48 ++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 docs/installer/building/Running-Tests-In-VisualStudio-IDE.md create mode 100644 src/installer/visual-studio-devenv.cmd diff --git a/docs/installer/building/Running-Tests-In-VisualStudio-IDE.md b/docs/installer/building/Running-Tests-In-VisualStudio-IDE.md new file mode 100644 index 0000000..2388907 --- /dev/null +++ b/docs/installer/building/Running-Tests-In-VisualStudio-IDE.md @@ -0,0 +1,19 @@ +# Running unit tests within Visual Studio + +Sometimes it is convenient to run individual unit tests within the Visual Studio IDE + +There are several environment variables which must be set to get this to work correctly. To make things easier there is a convenience script `visual-studio-devenv.cmd` provided. This script will set the necessary environment variables. + +## Steps + +1. `build.cmd` +2. `visual-studio-devenv.cmd` +3. Open the test explorer window within the Visual Studio IDE +4. Select tests and run and/or debug. + +## Limitations + +* The script is not yet designed to be a robust solution. As test configurations change this file could get out of date. The required configuration can be discovered by carefully examining the logs generated when running the tests with `build.cmd -MsBuildLogging=/bl`. The script can then be updated. +* The script is hardcoded to use the x64 debug build + + diff --git a/src/installer/run.cmd b/src/installer/run.cmd index b12a0f7..f86fcae 100644 --- a/src/installer/run.cmd +++ b/src/installer/run.cmd @@ -10,7 +10,7 @@ if exist %_VSWHERE% ( if not exist "%_VSCOMNTOOLS%" set _VSCOMNTOOLS=%VS140COMNTOOLS% if not exist "%_VSCOMNTOOLS%" ( echo Error: Visual Studio 2015 or 2017 required. - echo Please see https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/developer-guide.md for build instructions. + echo Please see https://github.com/dotnet/core-setup/blob/master/Documentation/building/windows-instructions.md for build instructions. exit /b 1 ) diff --git a/src/installer/visual-studio-devenv.cmd b/src/installer/visual-studio-devenv.cmd new file mode 100644 index 0000000..47d23af --- /dev/null +++ b/src/installer/visual-studio-devenv.cmd @@ -0,0 +1,48 @@ +@if "%_echo%" neq "on" echo off +setlocal +setlocal enableextensions +setlocal enabledelayedexpansion + +if defined VisualStudioVersion goto :Run + +set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" +if exist %_VSWHERE% ( + for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools +) +if not exist "%_VSCOMNTOOLS%" set _VSCOMNTOOLS=%VS140COMNTOOLS% +if not exist "%_VSCOMNTOOLS%" ( + echo Error: Visual Studio 2015 or 2017 required. + echo Please see https://github.com/dotnet/core-setup/blob/master/Documentation/building/windows-instructions.md for build instructions. + exit /b 1 +) + +set VSCMD_START_DIR="%~dp0" +call "%_VSCOMNTOOLS%\VsDevCmd.bat" + +:Run + +:: Makes test explorer work in Visual Studio by setting up environment variables for tests +:: See EnvironmentVariables around https://github.com/dotnet/core-setup/blob/master/src/test/dir.proj#L93 +:: Found the env vars by running build -MsBuildLogging=/bl, then look at the Exec task in RunTest target + +set CMD_START_DIR=%~dp0 +set NUGET_PACKAGES=%CMD_START_DIR%packages\ +set DOTNET_SDK_PATH=%CMD_START_DIR%Tools\dotnetcli\ + +set TEST_TARGETRID=win-x64 +set BUILDRID=win-x64 +set BUILD_ARCHITECTURE=x64 +set BUILD_CONFIGURATION=Debug + +set TEST_ARTIFACTS=%CMD_START_DIR%bin\tests\%TEST_TARGETRID%.%BUILD_CONFIGURATION%\ +set MNA_TFM=netcoreapp3.0 +set MNA_SEARCH=%CMD_START_DIR%bin\obj\%TEST_TARGETRID%.%BUILD_CONFIGURATION%\sharedFrameworkPublish\shared\Microsoft.NETCore.App\* + +:: We expect one hostfxr version directory in the MNA_SEARCH path +for /d %%i in (%MNA_SEARCH%) do ( + set MNA_PATH=%%i + ) + +set MNA_VERSION=%MNA_PATH:*sharedFrameworkPublish\shared\Microsoft.NETCore.App\=% + +devenv %CMD_START_DIR%\Microsoft.DotNet.CoreSetup.sln -- 2.7.4