I am writing a plugin for Nop Commerce and my HTML helpers are giving me intellisense errors. I get red lines underlining them and the errors:
Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification
Feature 'lambda expression' cannot be used because it is not part of the ISO-2 C# language specification
Here is my code:
@{
Layout = "";
}
@model Nop.Plugin.Widgets.HelloWorld.Models.ConfigurationModel
@using Nop.Web.Framework;
@Html.Action("StoreScopeConfiguration", "Setting", new { area = "Admin" })
@using (Html.BeginForm())
{
<fieldset>
<legend><strong>Hello World Configuration</strong></legend>
<table class="adminContent">
<tr>
<td class="adminTitle">
@Html.OverrideStoreCheckboxFor(model => model.Greeting_OverrideForStore, model => model.Greeting, Model.ActiveStoreScopeConfiguration)
@Html.NopLabelFor(model => model.Greeting):
</td>
<td class="adminData">
@Html.EditorFor(model => model.Greeting)
@Html.ValidationMessageFor(model => model.Greeting)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.OverrideStoreCheckboxFor(model => model.Name_OverrideForStore, model => model.Name, Model.ActiveStoreScopeConfiguration)
@Html.NopLabelFor(model => model.Name):
</td>
<td class="adminData">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</td>
</tr>
</table>
</fieldset>
<br />
<table class="adminContent">
<tr>
<td colspan="2">
<input type="submit" name="save" class="k-button" value="@T("Admin.Common.Save")" />
</td>
</tr>
</table>
}
My screen looks like:
I've looked for hours for the answer but haven't found one that actually works. The project is a code library and is on ASP.NET 4.5.1 like the rest of the solution. There are no errors when I build. Am I missing a reference or a using statement? I'm not sure what is going on.
The only way I was able to get this working (using VS2013) was to convert the Class Library projects into MVC projects:
- In
<PropertyGroup>
, add< ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}< /ProjectTypeGuids>
Add another import at the bottom:
< Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
Of course remove the extra space in the < tags>, it wasnt posting correct without them. There is a current bug issued on this with Microsoft here: https://connect.microsoft.com/VisualStudio/feedback/details/912301/intellisense-for-razor-in-class-libraries-not-working
The above answer about modifying the project from a Class Library to a MVC Project did not work for me as of VS2013 Update 4.
The following does work, however:
For all configurations, set Build, Output, Output Path to
bin\
and not..\..\Presentation\Nop.Web\Plugins\PLUGINNAMESPACE.PLUGINNAME\
as stated in nopCommerce documentation.In the .csproj file it should look like:
<OutputPath>bin\</OutputPath>
Set Build Events, Post-build command line: to copy to directory nopCommerce wants.
(robocopy $(ProjectDir)$(OutDir) $(ProjectDir)..\..\Presentation\Nop.Web\Plugins\PLUGINNAMESPACE.PLUGINNAME\ /MIR) ^& IF %ERRORLEVEL% LEQ 1 exit 0
In the .csproj file it should look like:
<PropertyGroup> <PostBuildEvent>(robocopy $(ProjectDir)$(OutDir) $(ProjectDir)..\..\Presentation\Nop.Web\Plugins\PLUGINNAMESPACE.PLUGINNAME\ /MIR) ^& IF %25ERRORLEVEL%25 LEQ 1 exit 0</PostBuildEvent> </PropertyGroup>
Setting Build Events, Run the post-build event: to "Always".
In the .csproj file it should look like:
<PropertyGroup> <RunPostBuildEvent>Always</RunPostBuildEvent> </PropertyGroup>
Ensure that every single DLL file Reference in your plugin project is set to Copy Local. This is not necessary for the ProjectReference entries like Nop.Core, Nop.Data etc. Again, this is not what they tell you to do in the nopCommerce documentation, but it is required to make Intellisense work.
In the .csproj file it should look like:
<Reference Include="System.Web"> <Private>True</Private> </Reference> (repeat for all DLL file references)...
Close and reopen the solution, rebuild the plugin project and now open any razor .cshtml files. Intellisense will work as expected and there is no need for any future hacks to maintain it.
The project needs to know its in plugin development
1: Close your solution 2: open your *.csproj file with any editor 3: Add the following near the end of the project closing tag
<Import Project="$(SolutionDir)\FixRazorIntellisense.targets" Condition="'$(Configuration)' == 'PluginDev'" />
4: reload the solution/project
来源:https://stackoverflow.com/questions/24175743/razor-html-helpers-giving-intellisense-errors-in-nop-commerce-plugin