Skip to content

Commit b61d16e

Browse files
committed
Cleanup in ScriptDependencyContextReader
1 parent 788ff3a commit b61d16e

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

src/Dotnet.Script.DependencyModel/Context/ScriptDependencyContextReader.cs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
using System.Linq;
55
using System.Reflection;
66
using System.Threading.Tasks;
7-
using System.Xml.Linq;
87
using Dotnet.Script.DependencyModel.Environment;
98
using Dotnet.Script.DependencyModel.Logging;
10-
using Dotnet.Script.DependencyModel.ProjectSystem;
119
using Dotnet.Script.DependencyModel.ScriptPackage;
12-
using Microsoft.DotNet.PlatformAbstractions;
1310
using NuGet.Common;
1411
using NuGet.Packaging;
1512
using NuGet.ProjectModel;
16-
using NuGet.RuntimeModel;
1713
using NuGet.Versioning;
18-
using Newtonsoft.Json;
1914
using Newtonsoft.Json.Linq;
2015

2116
namespace Dotnet.Script.DependencyModel.Context
@@ -72,7 +67,6 @@ public ScriptDependencyContext ReadDependencyContext(string pathToAssetsFile)
7267
var netcoreAppRuntimeAssemblies = Directory.GetFiles(netcoreAppRuntimeAssemblyLocation, "*.dll").Where(IsAssembly).ToArray();
7368
var netCoreAppDependency = new ScriptDependency("Microsoft.NETCore.App", ScriptEnvironment.Default.NetCoreVersion.Version, netcoreAppRuntimeAssemblies, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>());
7469
scriptDependencies.Add(netCoreAppDependency);
75-
//if (File.ReadAllText(pathToAssetsFile).Contains("\"Microsoft.AspNetCore.App\""))
7670
if (HasAspNetCoreFrameworkReference(pathToAssetsFile))
7771
{
7872
var aspNetCoreRuntimeInfo = GetAspNetCoreRuntimeInfo(netcoreAppRuntimeAssemblyLocation);
@@ -90,33 +84,20 @@ private bool HasAspNetCoreFrameworkReference(string pathToAssetsFile)
9084
return assetsFile["project"]?["frameworks"]?[ScriptEnvironment.Default.TargetFramework]?["frameworkReferences"]?["Microsoft.AspNetCore.App"] != null;
9185
}
9286

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-
10987
private static (string aspNetCoreRuntimeAssemblyLocation, string aspNetCoreVersion) GetAspNetCoreRuntimeInfo(string netcoreAppRuntimeAssemblyLocation)
11088
{
11189
var netCoreAppRuntimeVersion = Path.GetFileName(netcoreAppRuntimeAssemblyLocation);
11290
if (!SemanticVersion.TryParse(netCoreAppRuntimeVersion, out var version))
11391
{
114-
throw new InvalidOperationException("Unable to parse version");
92+
throw new InvalidOperationException($"Unable to parse netcore app version '{netCoreAppRuntimeVersion}'");
11593
}
11694
var pathToSharedFolder = Path.GetFullPath(Path.Combine(netcoreAppRuntimeAssemblyLocation, "..", ".."));
11795

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+
}
120101

121102
var aspNetCoreVersionsFolders = Directory.GetDirectories(pathToAspNetCoreRuntimeFolder).Select(folder => Path.GetFileName(folder));
122103

@@ -125,7 +106,7 @@ private static (string aspNetCoreRuntimeAssemblyLocation, string aspNetCoreVersi
125106
{
126107
if (!SemanticVersion.TryParse(aspNetCoreVersionsFolder, out var aspNetCoreVersion))
127108
{
128-
throw new InvalidOperationException("Unable to parse version");
109+
throw new InvalidOperationException($"Unable to parse Asp.Net version {aspNetCoreVersionsFolder}");
129110
}
130111
else
131112
{

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,6 @@ public void ShouldCompileAndExecuteWithWebSdk()
485485
{
486486
var processResult = ScriptTestRunner.Default.ExecuteFixture("WebApi", "--no-cache");
487487
Assert.Equal(0, processResult.ExitCode);
488-
489-
// var test = ScriptTestRunner.ExecuteFixtureInProcess("WebApi", "--no-cache --debug");
490-
// Assert.Equal(0, test);
491-
// var (output, _) = ScriptTestRunner.Default.ExecuteFixture("CurrentContextualReflectionContext", "--isolated-load-context");
492-
// Assert.Contains("Dotnet.Script.Core.ScriptAssemblyLoadContext", output);
493488
}
494489

495490
[Fact]

0 commit comments

Comments
 (0)