33using System ;
44using System . IO ;
55using System . Reflection ;
6+ using Microsoft . VisualStudio . TestPlatform . ObjectModel . Adapter ;
67
78namespace Microsoft . NodejsTools . TestAdapter
89{
@@ -13,11 +14,24 @@ public AssemblyResolver()
1314 AppDomain . CurrentDomain . AssemblyResolve += OnAssemblyResolve ;
1415 }
1516
17+ internal static string GetVSInstallDir ( )
18+ {
19+
20+ var vsTestFrameworkAssembly = typeof ( ITestExecutor ) . Assembly ;
21+ var testAdapterPath = vsTestFrameworkAssembly . Location ;
22+
23+ // C:\Program Files (x86)\Microsoft Visual Studio\2017\VSUJSLT\Common7\IDE\CommonExtensions\Microsoft\NodeJs Tools Unit Test Adapter\Microsoft.nodejstools.TestAdapter.dll
24+ var indexOfCommon7Ide = testAdapterPath . IndexOf ( "common7" , StringComparison . OrdinalIgnoreCase ) ;
25+ string vsInstallDir = testAdapterPath . Substring ( 0 , indexOfCommon7Ide ) ;
26+
27+ return vsInstallDir ;
28+ }
29+
1630 private static Assembly OnAssemblyResolve ( object sender , ResolveEventArgs args )
1731 {
1832 // Use the setup API to find the VS install Dir, then build paths to the Private and Public Assemblies folders
19- string installPath = @"C:\vs2017" ;
20- string ideFolder = Path . Combine ( installPath , "Common7\\ IDE" ) ;
33+ var installPath = GetVSInstallDir ( ) ;
34+ var ideFolder = Path . Combine ( installPath , "Common7\\ IDE" ) ;
2135 var paths = new [ ] {
2236 Path . Combine ( ideFolder , "PrivateAssemblies" ) ,
2337 Path . Combine ( ideFolder , "PublicAssemblies" ) ,
@@ -26,7 +40,7 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
2640
2741 // This is what comes in for args.Name, but we really just want the dll file name:
2842 // "Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
29- string resolveTargetAssemblyName = args . Name . Substring ( 0 , args . Name . IndexOf ( ',' ) ) + ".dll" ;
43+ var resolveTargetAssemblyName = args . Name . Substring ( 0 , args . Name . IndexOf ( ',' ) ) + ".dll" ;
3044
3145 foreach ( var path in paths )
3246 {
@@ -42,7 +56,7 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
4256 private static bool ResolveAssemblyPath ( string possibleDirectory , string assemblyName , out Assembly resolvedAssembly )
4357 {
4458 resolvedAssembly = null ;
45- string candidateAssemblyPath = Path . Combine ( possibleDirectory , assemblyName ) ;
59+ var candidateAssemblyPath = Path . Combine ( possibleDirectory , assemblyName ) ;
4660 if ( File . Exists ( candidateAssemblyPath ) )
4761 {
4862 resolvedAssembly = Assembly . LoadFrom ( candidateAssemblyPath ) ;
0 commit comments