简体   繁体   English

BuildProvider:是否可以指定要生成的程序集的名称?

[英]BuildProvider: Is it possible to specify the name of the assembly to be generated?

我创建了一个自定义的虚拟路径提供程序和构建提供程序,并且想知道是否可以以某种方式指定要生成的程序集的名称,而不是让asp.net给出一个名称?

To answer my own question, it is possible with little gymnastics. 要回答我自己的问题,很少做体操是可能的。 One can get reference to CodeDomProvider from AssemblyBuilder and from there on it is up to you what you want to do. 您可以从AssemblyBuilder获得对CodeDomProvider的引用,然后由您决定要做什么。 Something like this 像这样

 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            string outputName = VirtualPath.Substring(VirtualPath.LastIndexOf('/') + 1);
            outputName = outputName.Substring(0, outputName.LastIndexOf('.'));

            _compilationContext = (CompilationContext)HttpContext.Current.Items[outputName];

           // var tw = assemblyBuilder.CreateCodeFile(this);
           // tw.Write(_compilationContext.Content);
           // tw.Flush();
           // tw.Close();

            //TODO: inject this 
            var factory = new DirectCompilerServiceFactory();
            var compilerService = factory.CreateCompilerService(assemblyBuilder.CodeDomProvider);

            compilerService.CompileAssembly(_compilationContext);

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM