4
4
using System . Linq ;
5
5
using System . Reflection ;
6
6
using System . Threading . Tasks ;
7
- using System . Xml . Linq ;
8
7
using Dotnet . Script . DependencyModel . Environment ;
9
8
using Dotnet . Script . DependencyModel . Logging ;
10
- using Dotnet . Script . DependencyModel . ProjectSystem ;
11
9
using Dotnet . Script . DependencyModel . ScriptPackage ;
12
- using Microsoft . DotNet . PlatformAbstractions ;
13
10
using NuGet . Common ;
14
11
using NuGet . Packaging ;
15
12
using NuGet . ProjectModel ;
16
- using NuGet . RuntimeModel ;
17
13
using NuGet . Versioning ;
18
- using Newtonsoft . Json ;
19
14
using Newtonsoft . Json . Linq ;
20
15
21
16
namespace Dotnet . Script . DependencyModel . Context
@@ -72,7 +67,6 @@ public ScriptDependencyContext ReadDependencyContext(string pathToAssetsFile)
72
67
var netcoreAppRuntimeAssemblies = Directory . GetFiles ( netcoreAppRuntimeAssemblyLocation , "*.dll" ) . Where ( IsAssembly ) . ToArray ( ) ;
73
68
var netCoreAppDependency = new ScriptDependency ( "Microsoft.NETCore.App" , ScriptEnvironment . Default . NetCoreVersion . Version , netcoreAppRuntimeAssemblies , Array . Empty < string > ( ) , Array . Empty < string > ( ) , Array . Empty < string > ( ) ) ;
74
69
scriptDependencies . Add ( netCoreAppDependency ) ;
75
- //if (File.ReadAllText(pathToAssetsFile).Contains("\"Microsoft.AspNetCore.App\""))
76
70
if ( HasAspNetCoreFrameworkReference ( pathToAssetsFile ) )
77
71
{
78
72
var aspNetCoreRuntimeInfo = GetAspNetCoreRuntimeInfo ( netcoreAppRuntimeAssemblyLocation ) ;
@@ -90,33 +84,20 @@ private bool HasAspNetCoreFrameworkReference(string pathToAssetsFile)
90
84
return assetsFile [ "project" ] ? [ "frameworks" ] ? [ ScriptEnvironment . Default . TargetFramework ] ? [ "frameworkReferences" ] ? [ "Microsoft.AspNetCore.App" ] != null ;
91
85
}
92
86
93
- private static string GetPathToProjectFile ( string pathToAssetsFile )
94
- {
95
- var pathToProjectFile = Directory . GetFiles ( Path . Combine ( Path . GetDirectoryName ( pathToAssetsFile ) , ".." ) , "*.csproj" , SearchOption . TopDirectoryOnly ) . SingleOrDefault ( ) ;
96
- if ( pathToProjectFile is null )
97
- {
98
- pathToProjectFile = Directory . GetFiles ( Path . Combine ( Path . GetDirectoryName ( pathToAssetsFile ) , ".." , ".." , ".." , ScriptEnvironment . Default . TargetFramework ) , "*.csproj" , SearchOption . TopDirectoryOnly ) . SingleOrDefault ( ) ;
99
- }
100
-
101
- if ( pathToProjectFile is null )
102
- {
103
- throw new InvalidOperationException ( $ "Unable to locate project file based on { pathToAssetsFile } ") ;
104
- }
105
-
106
- return pathToProjectFile ;
107
- }
108
-
109
87
private static ( string aspNetCoreRuntimeAssemblyLocation , string aspNetCoreVersion ) GetAspNetCoreRuntimeInfo ( string netcoreAppRuntimeAssemblyLocation )
110
88
{
111
89
var netCoreAppRuntimeVersion = Path . GetFileName ( netcoreAppRuntimeAssemblyLocation ) ;
112
90
if ( ! SemanticVersion . TryParse ( netCoreAppRuntimeVersion , out var version ) )
113
91
{
114
- throw new InvalidOperationException ( "Unable to parse version" ) ;
92
+ throw new InvalidOperationException ( $ "Unable to parse netcore app version ' { netCoreAppRuntimeVersion } ' ") ;
115
93
}
116
94
var pathToSharedFolder = Path . GetFullPath ( Path . Combine ( netcoreAppRuntimeAssemblyLocation , ".." , ".." ) ) ;
117
95
118
- //Microsoft.AspNetCore.App
119
- var pathToAspNetCoreRuntimeFolder = Directory . GetDirectories ( pathToSharedFolder , "Microsoft.AspNetCore.App" , SearchOption . TopDirectoryOnly ) . Single ( ) ;
96
+ var pathToAspNetCoreRuntimeFolder = Directory . GetDirectories ( pathToSharedFolder , "Microsoft.AspNetCore.App" , SearchOption . TopDirectoryOnly ) . SingleOrDefault ( ) ;
97
+ if ( string . IsNullOrWhiteSpace ( pathToAspNetCoreRuntimeFolder ) )
98
+ {
99
+ throw new InvalidOperationException ( $ "Failed to resolve the path to 'Microsoft.AspNetCore.App' in { pathToSharedFolder } ") ;
100
+ }
120
101
121
102
var aspNetCoreVersionsFolders = Directory . GetDirectories ( pathToAspNetCoreRuntimeFolder ) . Select ( folder => Path . GetFileName ( folder ) ) ;
122
103
@@ -125,7 +106,7 @@ private static (string aspNetCoreRuntimeAssemblyLocation, string aspNetCoreVersi
125
106
{
126
107
if ( ! SemanticVersion . TryParse ( aspNetCoreVersionsFolder , out var aspNetCoreVersion ) )
127
108
{
128
- throw new InvalidOperationException ( "Unable to parse version" ) ;
109
+ throw new InvalidOperationException ( $ "Unable to parse Asp.Net version { aspNetCoreVersionsFolder } ") ;
129
110
}
130
111
else
131
112
{
0 commit comments