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

RazorViewEngineOptions.ParseOptions are hard to use #6009

Closed
DamianEdwards opened this issue Mar 22, 2017 · 7 comments
Closed

RazorViewEngineOptions.ParseOptions are hard to use #6009

DamianEdwards opened this issue Mar 22, 2017 · 7 comments
Assignees
Milestone

Comments

@DamianEdwards
Copy link
Member

Trying to set the C# lang version that Razor uses via the RazorViewEngineOptions.ParseOptions is a less-than-optimal experience right now, as the Roslyn types are immutable.

The following doesn't compile as ParseOptions.LanguageVersion is not settable:

services.AddMvc().AddRazorOptions(options =>
                options.ParseOptions.LanguageVersion = LanguageVersion.CSharp7);

The IntelliSense leads you down a path where this looks like what you should do, but it doesn't work, because WithLanguageVersion returns a new instance of ParseOptions which gets lost to the ether:

services.AddMvc().AddRazorOptions(options =>
                options.ParseOptions.WithLanguageVersion(LanguageVersion.CSharp7));

This is actually what you need to do:

services.AddMvc().AddRazorOptions(options =>
                options.ParseOptions = new CSharpParseOptions(LanguageVersion.CSharp7));

Or probably more correctly:

services.AddMvc().AddRazorOptions(options =>
                options.ParseOptions = options.ParseOptions.WithLanguageVersion(LanguageVersion.CSharp7));

Not really sure we can do anything about this given the types are designed this way.

@benaadams
Copy link
Contributor

ref return ParseOptions ?

@rynowak
Copy link
Member

rynowak commented Mar 22, 2017

IMO we should not support/expose this at all. It's confusing and we don't really do what it says.

Here are all 20 reasons why:

  • Changing this setting doesn't help because Razor doesn't respect it
  • No I'm not referring to how we don't currently have support for C#7
  • What I mean is that when we do have support for C#7, it won't be possible for Razor's understanding of C# won't revert back to C#6
  • This may do the right thing, or may not, but we shouldn't advertise it if we're not going to test it
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything
  • Putting a Roslyn type like this in DI via options causes a LOT of things to be jitted even when we don't compile anything

@pranavkm
Copy link
Contributor

@davidfowl who asked for this feature. I think you're right - we should probably have a select set of things exposed on view engine options (additional references for instance). We could have extensibility \ replacability around things like CSharpCompiler in the event the user actually wants to meddle with the compilation rather than having it exposed on such a publicly visible type.

@rynowak rynowak self-assigned this Apr 10, 2017
@rynowak rynowak added this to the 2.0.0-preview1 milestone Apr 10, 2017
@rynowak
Copy link
Member

rynowak commented Apr 10, 2017

@Eilon @davidfowl @DamianEdwards - my proposal is to remove this from options and try to remove this from the startup path unless you actually need it.

I think this is a holdover from DNX days.

@rynowak rynowak modified the milestones: 2.0.0-preview2, 2.0.0-preview3 May 30, 2017
@pranavkm
Copy link
Contributor

pranavkm commented Jul 3, 2017

@rynowak where did we land on this?

@rynowak
Copy link
Member

rynowak commented Jul 3, 2017

I haven't started this yet. If you think you can get it done today that would be a load of of my mind 👍

@pranavkm
Copy link
Contributor

pranavkm commented Jul 3, 2017

Sure, I can take over this.

pranavkm added a commit that referenced this issue Jul 5, 2017
#6487)

* Remove ParseOptions and CompilationOptions from RazorViewEngineOptions

Fixes #6009
pranavkm added a commit to aspnet/MvcPrecompilation that referenced this issue Jul 5, 2017
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

5 participants