Intellisense in Plugin Views

How to enable Intellisense in plugin views

To get Intellisense in plugin views up and running, you have to switch your project configuration to PluginDev before editing any view file. This configuration ensures that all required dependencies for Razor dynamic compilation are copied into the correct folder (subdirectory bin\ of the plugin project).

If you want to enable Intellisense for your own plugin project, you have to add two little code snippets to the csproj project file manually. Just ensure that the project is not loaded in Visual Studio and open the file in a text editor.

Add the following snippet to the bottom, right before the closing Project tag:

<Import Project="$(SolutionDir)\FixRazorIntellisense.targets" Condition="'$(Configuration)' == 'PluginDev'" />

 

This specified build file only gets imported when the current configuration is PluginDev. It is then responsible for copying all references, regardless of the CopyLocal attribute value.

Another very useful snippet ensures that CopyLocal always defaults to false:

<ItemDefinitionGroup>
  <Reference>
    <Private>False</Private>
  </Reference>
  <ProjectReference>
    <Private>False</Private>
  </ProjectReference>
</ItemDefinitionGroup>

 

Place this at the top, right after the opening Project tag.

Some background info: Visual Studio's default for CopyLocal is true, which means that nearly all references are copied to the output directory. This can slow down the build process dramatically. Furthermore. the output directory for plugins is usually {build}/Plugins/{ThePlugin}. When the app starts, the dll files within this directory get shadow copied over to a shared bin directory, which already contains most of the referenced files (such as the very common Autofac). To prevent this redundancy and disk space waste, you simply suppress this behavior by defaulting CopyLocal to false.

Of course, you could also set this attribute manually in the properties window of Visual Studio, but with the next NuGet package update, your setting would be reset. Therefore, the better approach would be to keep references private by default and set CopyLocal to true explicitly, when the reference is really private (i.e. no other project in the solution refers to it).