Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

RoslynCompilationService to flow generated code when compilation is successful #895

Closed
kichalla opened this issue Jul 29, 2014 · 4 comments
Labels

Comments

@kichalla
Copy link
Member

I was curious to see how the autogenerated files would look like,so i tried using IRazorCompilationService to get the generated code, but i noticed that the default implementation of this service (RoslynCompilationService) does not set the property GeneratedCode for me to get the information...

From RoslynCompilationService.cs:

return CompilationResult.Successful(string.Empty, type);

My code:

services.AddSingleton<IRazorCompilationService, WrapperCompilationService>();
//--------------
public class WrapperCompilationService : IRazorCompilationService
{
    RazorCompilationService defaultService = null;
    public WrapperCompilationService(IApplicationEnvironment environment,
                                    ICompilationService compilationService,
                                    IMvcRazorHost razorHost)
    {
        defaultService = new RazorCompilationService(environment, compilationService, razorHost);
    }

    public CompilationResult Compile(IFileInfo fileInfo)
    {
        CompilationResult result = defaultService.Compile(fileInfo);

        using (StreamWriter sw = new StreamWriter(File.Create(
            string.Format(@"C:\RazorGeneratedFiles\{0}_{1}",result.CompiledType.FullName, Guid.NewGuid()))))
        {
            sw.Write(result.GeneratedCode);
        }

        return result;
    }
}
@yishaigalatzer
Copy link
Contributor

@pranavkm I think this is already part of your compilation change, if so please close this issue

@davidfowl
Copy link
Member

Why is this still working /cc @danroth27 @yishaigalatzer

@yishaigalatzer yishaigalatzer changed the title RoslynCompilationService is not setting the generated code when compilation is successful RoslynCompilationService to flow generated code when compilation is successful Oct 6, 2014
@kichalla kichalla removed this from the 6.0.0-alpha4 milestone Dec 19, 2014
@kichalla
Copy link
Member Author

Re-opening this issue as it was originally fixed but got regressed due to the following commit:
6600e68#diff-8fe1e17d71f328d3f4fbff84450b9f51L108

@pranavkm @yishaigalatzer

@kichalla kichalla reopened this Dec 19, 2014
@yishaigalatzer
Copy link
Contributor

Please open a separate issue and details the exact broken scenario. Also note that if example if you are using precompilation you will not get the generated code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants