Esempio n. 1
0
        protected virtual CSharpCompilation AddToCompilation(CSharpCompilation compilation, DefaultViewCompilerCodeEmitter emitter, string fileName, string namespaceName, string className)
        {
            var tree = emitter.BuildTree(namespaceName, className, fileName);

            return(compilation
                   .AddSyntaxTrees(tree)
                   .AddReferences(emitter.UsedAssemblies
                                  .Select(a => assemblyCache.GetAssemblyMetadata(a))));
        }
        public virtual CSharpCompilation CreateCompilation(string assemblyName)
        {
            var diAssembly = typeof(ServiceCollection).Assembly;

            var references = diAssembly.GetReferencedAssemblies().Select(Assembly.Load)
                             .Concat(markupConfiguration.Assemblies.Select(e => Assembly.Load(new AssemblyName(e))))
                             .Concat(new[] {
                diAssembly,
                Assembly.Load(new AssemblyName("mscorlib")),
                Assembly.Load(new AssemblyName("System.ValueTuple")),
                typeof(IServiceProvider).Assembly,
                typeof(RuntimeBinderException).Assembly,
                typeof(DynamicAttribute).Assembly,
                typeof(DotvvmConfiguration).Assembly,
#if DotNetCore
                Assembly.Load(new AssemblyName("netstandard")),
                Assembly.Load(new AssemblyName("System.Runtime")),
                Assembly.Load(new AssemblyName("System.Collections.Concurrent")),
                Assembly.Load(new AssemblyName("System.Collections")),
#else
                typeof(List <>).Assembly
#endif
            })
                             .Distinct();

            return(CSharpCompilation.Create(assemblyName, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
                   .AddReferences(references.Select(a => assemblyCache.GetAssemblyMetadata(a))));
        }
Esempio n. 3
0
        protected virtual CSharpCompilation AddToCompilation(CSharpCompilation compilation, DefaultViewCompilerCodeEmitter emitter, string fileName, string namespaceName, string className)
        {
            var tree = emitter.BuildTree(namespaceName, className, fileName);

            return(compilation
                   .AddSyntaxTrees(tree)
                   .AddReferences(emitter.UsedAssemblies
                                  .Select(a => assemblyCache.GetAssemblyMetadata(a.Key).WithAliases(ImmutableArray.Create(a.Value, "global")))));
        }
Esempio n. 4
0
        public virtual CSharpCompilation CreateCompilation(string assemblyName)
        {
            return(CSharpCompilation.Create(assemblyName).AddReferences(new[]
            {
                typeof(RuntimeBinderException).GetTypeInfo().Assembly,
                typeof(System.Runtime.CompilerServices.DynamicAttribute).GetTypeInfo().Assembly,
                typeof(DotvvmConfiguration).GetTypeInfo().Assembly,
                Assembly.Load(new AssemblyName("mscorlib")),
#if DotNetCore
                Assembly.Load(new AssemblyName("System.Runtime")),
                Assembly.Load(new AssemblyName("System.Collections.Concurrent")),
                Assembly.Load(new AssemblyName("System.Collections")),
                Assembly.Load(new AssemblyName("System.ValueTuple")),
                Assembly.Load(new AssemblyName("netstandard")),
#else
                typeof(System.Collections.Generic.List <>).Assembly
#endif
            }.Concat(configuration.Markup.Assemblies.Select(e => Assembly.Load(new AssemblyName(e)))).Distinct()
                                                                        .Select(a => assemblyCache.GetAssemblyMetadata(a)))
                   .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)));
        }
Esempio n. 5
0
        public virtual CSharpCompilation CreateCompilation(string assemblyName)
        {
            var diAssembly = typeof(ServiceCollection).Assembly;

            var references = diAssembly.GetReferencedAssemblies().Select(Assembly.Load)
                             .Concat(markupConfiguration.Assemblies.Select(e => Assembly.Load(new AssemblyName(e))))
                             .Concat(new[] {
                diAssembly,
                Assembly.Load(new AssemblyName("mscorlib")),
                Assembly.Load(new AssemblyName("System.ValueTuple")),
                typeof(IServiceProvider).Assembly,
                typeof(RuntimeBinderException).Assembly,
                typeof(DynamicAttribute).Assembly,
                typeof(DotvvmConfiguration).Assembly,
#if DotNetCore
                Assembly.Load(new AssemblyName("System.Runtime")),
                Assembly.Load(new AssemblyName("System.Collections.Concurrent")),
                Assembly.Load(new AssemblyName("System.Collections")),
#else
                typeof(List <>).Assembly
#endif
            });

            try
            {
                // netstandard assembly is required for netstandard 2.0 and in some cases
                // for netframework461 and newer. netstandard is not included in netframework452
                // and will throw FileNotFoundException. Instead of detecting current netframework
                // version, the exception is swallowed.
                references = references.Concat(new[] { Assembly.Load(new AssemblyName("netstandard")) });
            }
            catch (FileNotFoundException) { }

            return(CSharpCompilation.Create(assemblyName, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
                   .AddReferences(references.Distinct().Select(a => assemblyCache.GetAssemblyMetadata(a))));
        }
Esempio n. 6
0
 public virtual CSharpCompilation CreateCompilation(string assemblyName)
 {
     return(CSharpCompilation.Create(assemblyName, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
            .AddReferences(referencedAssembliesCache.Value.Select(a => assemblyCache.GetAssemblyMetadata(a))));
 }