开发者

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

I created a custom virtual path provider and build provider and was wondering if it was possible to somehow specify the name of the assembly that get's generated, rather then letting asp.net com开发者_开发技巧e up with a name?


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. 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);

        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜