Skip to content

Commit

Permalink
use assembly loader and fixed issues after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
filipw committed Jun 27, 2017
1 parent d07f012 commit cd7b3c3
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/OmniSharp.Script/ScriptProjectSystem.cs
Expand Up @@ -30,15 +30,19 @@ public class ScriptProjectSystem : IProjectSystem
private readonly OmniSharpWorkspace _workspace;
private readonly IOmniSharpEnvironment _env;
private readonly ILogger _logger;
private readonly IAssemblyLoader _assemblyLoader;

private readonly IScriptProjectProvider _scriptProjectProvider;
private static readonly Lazy<string> _targetFrameWork = new Lazy<string>(ResolveTargetFramework);

[ImportingConstructor]
public ScriptProjectSystem(OmniSharpWorkspace workspace, IOmniSharpEnvironment env, ILoggerFactory loggerFactory, MetadataFileReferenceCache metadataFileReferenceCache)
public ScriptProjectSystem(OmniSharpWorkspace workspace, IOmniSharpEnvironment env, ILoggerFactory loggerFactory,
MetadataFileReferenceCache metadataFileReferenceCache, IAssemblyLoader assemblyLoader)
{
_metadataFileReferenceCache = metadataFileReferenceCache;
_workspace = workspace;
_env = env;
_assemblyLoader = assemblyLoader;
_logger = loggerFactory.CreateLogger<ScriptProjectSystem>();
_projects = new Dictionary<string, ProjectInfo>();
_scriptProjectProvider = ScriptProjectProvider.Create(loggerFactory);
Expand Down Expand Up @@ -73,10 +77,6 @@ public void Initalize(IConfiguration configuration)
x.Name.ToLowerInvariant().StartsWith("system.valuetuple")));

var runtimeContexts = File.Exists(Path.Combine(_env.TargetDirectory, "project.json")) ? ProjectContext.CreateContextForEachTarget(_env.TargetDirectory) : null;
var runtimeContext = runtimeContexts?.FirstOrDefault();

var commonReferences = new HashSet<MetadataReference>();

if (!bool.TryParse(configuration["enableScriptNuGetReferences"], out var enableScriptNuGetReferences))
{
enableScriptNuGetReferences = false;
Expand All @@ -87,6 +87,9 @@ public void Initalize(IConfiguration configuration)
runtimeContexts = TryCreateRuntimeContextsFromScriptFiles();
}

var runtimeContext = runtimeContexts?.FirstOrDefault();
var commonReferences = new HashSet<MetadataReference>();

// if we have no context, then we also have no dependencies
// we will assume desktop framework
// and add default CLR references
Expand Down Expand Up @@ -153,8 +156,8 @@ private void AddDefaultClrMetadataReferences(ProjectContext projectContext, Hash
typeof(Enumerable).GetTypeInfo().Assembly,
typeof(Stack<>).GetTypeInfo().Assembly,
typeof(Lazy<,>).GetTypeInfo().Assembly,
FromName("System.Runtime"),
FromName("mscorlib")
_assemblyLoader.Load("System.Runtime"),
_assemblyLoader.Load("mscorlib")
};

var references = assemblies
Expand All @@ -167,18 +170,6 @@ private void AddDefaultClrMetadataReferences(ProjectContext projectContext, Hash
{
commonReferences.Add(reference);
}

Assembly FromName(string assemblyName)
{
try
{
return Assembly.Load(new AssemblyName(assemblyName));
}
catch
{
return null;
}
}
}
}

Expand Down

0 comments on commit cd7b3c3

Please sign in to comment.