问题
I'm hoping someone can help me out with this annoyance.
At work we have two independent website projects that share a common MasterPage. The MasterPage is embedded in a class library that both projects reference. We use a custom VirtualPathProvider that lets us reference the MasterPage in each project. This works fine at runtime/compiletime, but it breaks intellisense inside the aspx page markup.
When I set the MasterPageFile property to "~/EmbeddedMasterPage.Master", Visual Studio shows a red squiggley error under it saying "Path not found", with a directory indicating that it's trying to find that file inside the website project(as opposed to the class library project). Since Visual Studio can't figure out where the MasterPage is, it's causing all of the intellisense to break. It won't show anything for the tags. In fact, the only intellisense it will give me is for basic html tags. From Googling around, the only information I could find is that VS can't find the root html/head/body tags in the embedded MasterPage. I couldn't find a way to fix it, though.
This happens in both Visual Studio 2008 and 2010.
Update(4/10/2011)
For the time being, I'm having to copy the embedded masterpage to the actual site project in order to get it to work. I set the file to not compile/copy and it works out ok.
回答1:
The VirtualPathProvider requires the run-time environment. During design time this is not available, so there is no way to get the IDE to find it via VirtualPathProvider.
I think your update is the best workaround.
来源:https://stackoverflow.com/questions/5364129/asp-net-virtualpathprovider-and-visual-studio-intellisense