-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update default Razor search paths to include ~/[PagesRoot]/Shared #6783
Conversation
options.ViewLocationExpanders.Add(new PageViewLocationExpander()); | ||
} | ||
|
||
private static string CombinePath(string path1, string path2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not Path.Combine
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to preserve path separators (they are all meant to be forward slashes). Path.Combine
canonicalizes paths to use OS dependent path separators.
} | ||
|
||
var rootDirectory = _pagesOptions.RootDirectory; | ||
Debug.Assert(!string.IsNullOrEmpty(rootDirectory)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These shouldn't be asserts, they are clearly possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We disallow these in the property setter (https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.RazorPages/RazorPagesOptions.cs#L32), but sure, we can throw for extra goodness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, unimportant then
options.PageViewLocationFormats.Add("/Views/Shared/{0}" + RazorViewEngine.ViewExtension); | ||
|
||
options.ViewLocationFormats.Add(pagesSharedDirectory); | ||
options.AreaViewLocationFormats.Add(pagesSharedDirectory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait so we're making pages/shared searchable from views too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's how @DamianEdwards wants this. The intent is to allow folks to migrate from Views -> Pages while keeping things working.
|
||
namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal | ||
{ | ||
public class RazorPagesRazorViewEngineOptionsSetupTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs two functional tests. (View -> Pages/Shared), (Page -> Pages/Shared)
I don't think there's anywhere else in the system we unit test options setups 😆
return path1 + path2 + RazorViewEngine.ViewExtension; | ||
} | ||
|
||
return path1 + "/" + path2 + RazorViewEngine.ViewExtension; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since path1 is always _pagesOptions.RootDirectory
do we guarantee the absence of a trailing slash? or do we allow that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what the check in line #47 does, no?
2b8b243
to
b8f61fd
Compare
🆙 📅 |
Fixes #6604