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

Tool produces a 0-byte binary when compilation fails #35

Closed
pranavkm opened this issue Nov 21, 2016 · 9 comments
Closed

Tool produces a 0-byte binary when compilation fails #35

pranavkm opened this issue Nov 21, 2016 · 9 comments
Assignees

Comments

@pranavkm
Copy link
Contributor

Steps:

  1. Create a view with a compilation error (e.g. int x = "Hello world";)
  2. Run dotnet-razor-precompile on the app with the right arguments.

Expected:
View compilation fails and no .Precompiled.dll binary is produced.

Actual:
View compilation fails and a 0-byte binary is produced.

@Eilon
Copy link
Member

Eilon commented Nov 21, 2016

Is this really a bug in precompilation (we always create a stream for the PE file?), or is it possibly a bug on Roslyn or something?

@pranavkm
Copy link
Contributor Author

It's the former. Compilation errors are exposed as part of emitting the binary and we create a file stream to emit it. I'll have a look at what csc does to see if there's a better way to do this.

@Eilon Eilon added this to the 1.2.0 milestone Nov 21, 2016
@pranavkm
Copy link
Contributor Author

Looks like they're using API's not publicly available to produce diagnostics without having a Stream (https://github.com/dotnet/roslyn/blob/2d871994b396f7ceca6722464f5b8c85905b343e/src/Compilers/Core/Portable/Compilation/Compilation.cs#L1643). I'll just remove the file in the event compilation fails.

@Eilon
Copy link
Member

Eilon commented Nov 21, 2016

Eh that's ugly. Can we get a recommendation from Roslyn on how to do this?

@pranavkm
Copy link
Contributor Author

I can ask. The other alternative is to write to a memory stream (which is what we do at runtime) and copy to disk if it's successful.

@pranavkm
Copy link
Contributor Author

DNX used the MemoryStream pattern - emit in memory followed by a copy if success: https://github.com/aspnet/dnx/blob/bebc991012fe633ecac69675b2e892f568b927a5/src/Microsoft.Dnx.Compilation.CSharp/RoslynProjectReference.cs#L243-L251. It's some extra overhead if everything goes well, but I suppose it does a clean no-op.

@Eilon
Copy link
Member

Eilon commented Nov 21, 2016

I think I prefer that. Write to disk only when it's safe.

@pranavkm
Copy link
Contributor Author

pranavkm commented Nov 23, 2016

@Eilon could we consider this for 1.1.1? The experience without this change is pretty bad. @DamianEdwards seemed interested in this

@Eilon
Copy link
Member

Eilon commented Nov 23, 2016

Let's get this into 1.2.0 as you have it, and log a new bug for 1.1.1 to track porting this.

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

No branches or pull requests

2 participants