Disable custom ViewEngine processing
Hello,
in our project, we have custom ViewEngine, that is trying to search for files in some custom locations.
When is nothing found, it uses default path.
Here is some code:
private readonly string[] newLocations =
{
"~/Segments/%1%/Views/{1}/{0}.cshtml",
"~/Segments/%1%/Views/{1}/{0}.vbhtml",
"~/Segments/%1%/Views/Shared/{0}.cshtml",
"~/Segments/%1%/Views/Shared/{0}.vbhtml"
};
public CustomRazorViewEngine()
{
ViewLocationFormats = PrependLocationFormats(this.newLocations, ViewLocationFormats);
MasterLocationFormats = PrependLocationFormats(this.newLocations, MasterLocationFormats);
PartialViewLocationFormats = PrependLocationFormats(this.newLocations, PartialViewLocationFormats);
}
private static string[] PrependLocationFormats(IEnumerable<string> newLocations, IEnumerable<string> defaultLocations)
{
var viewLocations = new List<string>();
viewLocations.AddRange(newLocations);
viewLocations.AddRange(defaultLocations);
return viewLocations.ToArray();
}
The problem is with the "%1%" part - this is dynamic path that we are handling also in this engine and we are replacing it with one of few account types (depending on logged user).
The point is, that Resharper uses this list of locations and is trying to find files in there.
And this is causing every view reference to be red (not resolved).
I want to turn this feature off (or ignore this ViewEngine) - we have most of our views in default location, so it will be alright.
I tried adding this ViewEngine.cs file and Global.asax.cs file to ignored files for Code Analys, but it still takes it.
Can someone help?
Please sign in to leave a comment.
Hello Tomas!
Thank you for contacting us.
Could you please provide screenshot illustrating the problem?
Thank you.