Simplify how we pick dependencies for razor compilation

This commit is contained in:
David Fowler 2014-03-08 17:15:16 -08:00
parent bda7dd8d2d
commit e62e5a2bef
1 changed files with 16 additions and 16 deletions

View File

@ -66,17 +66,26 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
private List<MetadataReference> GetApplicationReferences() private List<MetadataReference> GetApplicationReferences()
{ {
var references = new List<MetadataReference>(); var references = new List<MetadataReference>();
var applicationExport = _exporter.GetDependencyExport(_environment.ApplicationName, _environment.TargetFramework);
// HACK: This is a hack, we need a way to get the application's dependencies. // TODO: We need a way to get the current application's dependencies
// Today this is relying on dynamic compilation
ExtractReferences(applicationExport, references, expandCompilationReferences: true);
var assemblies = new[] { var assemblies = new[] {
_environment.ApplicationName,
#if NET45
"mscorlib",
"System",
"System.Core",
"Microsoft.CSharp",
#else
"System.Linq", "System.Linq",
"System.Collections",
"System.Dynamic", "System.Dynamic",
"System.Dynamic.Runtime", "System.Dynamic.Runtime",
typeof(HtmlString).GetTypeInfo().Assembly.GetName().Name "System.Collections.Generic",
#endif
"Microsoft.AspNet.Mvc",
"Microsoft.AspNet.Mvc.Razor",
"Microsoft.AspNet.Mvc.Rendering",
}; };
foreach (var assemblyName in assemblies) foreach (var assemblyName in assemblies)
@ -88,13 +97,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
continue; continue;
} }
ExtractReferences(export, references, expandCompilationReferences: false); ExtractReferences(export, references);
} }
return references; return references;
} }
private void ExtractReferences(IDependencyExport export, List<MetadataReference> references, bool expandCompilationReferences) private void ExtractReferences(IDependencyExport export, List<MetadataReference> references)
{ {
foreach (var metadataReference in export.MetadataReferences) foreach (var metadataReference in export.MetadataReferences)
{ {
@ -121,15 +130,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
if (roslynReference != null) if (roslynReference != null)
{ {
references.Add(roslynReference.MetadataReference); references.Add(roslynReference.MetadataReference);
if (expandCompilationReferences)
{
var compilatonReference = roslynReference.MetadataReference as CompilationReference;
if (compilatonReference != null)
{
references.AddRange(compilatonReference.Compilation.References);
}
}
} }
} }
} }