@ -61,29 +61,30 @@ namespace ICSharpCode.Decompiler.Metadata
@@ -61,29 +61,30 @@ namespace ICSharpCode.Decompiler.Metadata
} ;
readonly DotNetCorePackageInfo [ ] packages ;
ISet < string > packageBasePaths = new HashSet < string > ( StringComparer . Ordinal ) ;
readonly Version version ;
readonly List < string > searchPaths = new List < string > ( ) ;
readonly List < string > packageBasePaths = new List < string > ( ) ;
readonly Version targetFrameworkVersion ;
readonly string dotnetBasePath = FindDotNetExeDirectory ( ) ;
public DotNetCorePathFinder ( Version v ersion)
public DotNetCorePathFinder ( Version targetFrameworkV ersion)
{
this . version = v ersion;
this . targetFrameworkVersion = targetFrameworkV ersion;
}
public DotNetCorePathFinder ( string parentAssemblyFileName , string targetFrameworkIdString , TargetFrameworkIdentifier targetFramework , Version v ersion, ReferenceLoadInfo loadInfo = null )
public DotNetCorePathFinder ( string parentAssemblyFileName , string targetFrameworkIdString , TargetFrameworkIdentifier targetFramework , Version targetFrameworkV ersion, ReferenceLoadInfo loadInfo = null )
{
string assemblyName = Path . GetFileNameWithoutExtension ( parentAssemblyFileName ) ;
string basePath = Path . GetDirectoryName ( parentAssemblyFileName ) ;
this . version = v ersion;
this . targetFrameworkVersion = targetFrameworkV ersion;
if ( targetFramework = = TargetFrameworkIdentifier . NETStandard ) {
// .NET Standard 2.1 is implemented by .NET Core 3.0 or higher
if ( v ersion. Major = = 2 & & v ersion. Minor = = 1 ) {
this . v ersion = new Version ( 3 , 0 , 0 ) ;
if ( targetFrameworkV ersion. Major = = 2 & & targetFrameworkV ersion. Minor = = 1 ) {
this . targetFrameworkV ersion = new Version ( 3 , 0 , 0 ) ;
}
}
packageBase Paths. Add ( basePath ) ;
search Paths. Add ( basePath ) ;
var depsJsonFileName = Path . Combine ( basePath , $"{assemblyName}.deps.json" ) ;
if ( File . Exists ( depsJsonFileName ) ) {
@ -106,17 +107,17 @@ namespace ICSharpCode.Decompiler.Metadata
@@ -106,17 +107,17 @@ namespace ICSharpCode.Decompiler.Metadata
public void AddSearchDirectory ( string path )
{
this . packageBase Paths. Add ( path ) ;
this . search Paths. Add ( path ) ;
}
public void RemoveSearchDirectory ( string path )
{
this . packageBase Paths. Remove ( path ) ;
this . search Paths. Remove ( path ) ;
}
public string TryResolveDotNetCore ( IAssemblyReference name )
{
foreach ( var basePath in packageBasePaths ) {
foreach ( var basePath in searchPaths . Concat ( packageBasePaths ) ) {
if ( File . Exists ( Path . Combine ( basePath , name . Name + ".dll" ) ) ) {
return Path . Combine ( basePath , name . Name + ".dll" ) ;
} else if ( File . Exists ( Path . Combine ( basePath , name . Name + ".exe" ) ) ) {
@ -124,7 +125,7 @@ namespace ICSharpCode.Decompiler.Metadata
@@ -124,7 +125,7 @@ namespace ICSharpCode.Decompiler.Metadata
}
}
return FallbackToDotNetSharedDirectory ( name , version ) ;
return FallbackToDotNetSharedDirectory ( name ) ;
}
internal string GetReferenceAssemblyPath ( string targetFramework )
@ -169,7 +170,7 @@ namespace ICSharpCode.Decompiler.Metadata
@@ -169,7 +170,7 @@ namespace ICSharpCode.Decompiler.Metadata
}
}
string FallbackToDotNetSharedDirectory ( IAssemblyReference name , Version version )
string FallbackToDotNetSharedDirectory ( IAssemblyReference name )
{
if ( dotnetBasePath = = null )
return null ;
@ -177,7 +178,7 @@ namespace ICSharpCode.Decompiler.Metadata
@@ -177,7 +178,7 @@ namespace ICSharpCode.Decompiler.Metadata
foreach ( var basePath in basePaths ) {
if ( ! Directory . Exists ( basePath ) )
continue ;
var closestVersion = GetClosestVersionFolder ( basePath , v ersion) ;
var closestVersion = GetClosestVersionFolder ( basePath , targetFrameworkV ersion) ;
if ( File . Exists ( Path . Combine ( basePath , closestVersion , name . Name + ".dll" ) ) ) {
return Path . Combine ( basePath , closestVersion , name . Name + ".dll" ) ;
} else if ( File . Exists ( Path . Combine ( basePath , closestVersion , name . Name + ".exe" ) ) ) {
@ -189,15 +190,17 @@ namespace ICSharpCode.Decompiler.Metadata
@@ -189,15 +190,17 @@ namespace ICSharpCode.Decompiler.Metadata
static string GetClosestVersionFolder ( string basePath , Version version )
{
string result = null ;
foreach ( var folder in new DirectoryInfo ( basePath ) . GetDirectories ( ) . Select ( d = > ConvertToVersion ( d . Name ) ) . Where ( v = > v . Item1 ! = null ) . OrderByDescending ( v = > v . Item1 ) ) {
if ( folder . Item1 > = version )
result = folder . Item2 ;
var foundVersions = new DirectoryInfo ( basePath ) . GetDirectories ( )
. Select ( d = > ConvertToVersion ( d . Name ) )
. Where ( v = > v . version ! = null ) ;
foreach ( var folder in foundVersions . OrderBy ( v = > v . Item1 ) ) {
if ( folder . version > = version )
return folder . directoryName ;
}
return result ? ? version . ToString ( ) ;
return version . ToString ( ) ;
}
internal static ( Version , string ) ConvertToVersion ( string name )
internal static ( Version version , string directoryName ) ConvertToVersion ( string name )
{
string RemoveTrailingVersionInfo ( )
{