所以我用nuGet安装了RazorGenerator并添加了VS扩展(感谢Visual Studio cannot find custom tool RazorGenerator)。
只是在我现有的mvc应用程序上试用它,我在其中一个视图上将自定义工具更改为RazorGenerator,并使用右键单击选项"运行自定义工具"生成代码。代码确实是创建的。
然后我构建整个应用程序并尝试运行它,在旧的剃刀脚本和新的预编译代码中设置断点。令我惊讶的是,它仍在运行旧的脚本代码,而不是新代码。我错过了某个地方,将执行切换到新代码。文档有点吝啬,但如果需要的话,你会认为像这样的重要内容会被提及。我知道它使用WebActivatorEx.PostApplicationStartMethod()来调用App_Start中的引导代码,或者至少它曾经这样做过,但是在每次调试开始时似乎都没有这样做,甚至在iisreset之后也没有。如果我尝试删除源razor视图,则返回结果时ajax调用失败,因此显然不使用预编译代码。我在某处错过了一步吗?
我注意到的一件事是,当我在生成的代码中的Excecute()方法中放置一个断点时,它告诉我"断点当前不会被命中。调试器的目标代码的可执行代码不与该行相关联。是否生成了正确的代码?
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ASP
{
using System;
using System.Collections.Generic;
#line 2 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
using System.Data;
#line default
#line hidden
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Routing;
using System.Web.Security;
using System.Web.UI;
using System.Web.WebPages;
#line 3 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
using Core.Models.Organization.Table;
#line default
#line hidden
#line 4 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
using Core.ViewModels.Base;
#line default
#line hidden
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
[System.Web.WebPages.PageVirtualPathAttribute("~/Areas/Views/GenericTable/DataCurrent.cshtml")]
public partial class _Areas_Views_GenericTable_DataCurrent_cshtml : System.Web.Mvc.WebViewPage<GenericTableDataCurrent>
{
public _Areas_Views_GenericTable_DataCurrent_cshtml()
{
}
public override void Execute()
{
WriteLiteral("\r\n");
#line 6 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Response.ContentType = "text/xml";
Layout = null;
#line default
#line hidden
WriteLiteral("\r\n<rows");
WriteAttribute("total_count", Tuple.Create(" total_count=\"", 240), Tuple.Create("\"", 271)
#line 10 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
, Tuple.Create(Tuple.Create("", 254), Tuple.Create<System.Object, System.Int32>(Model.TotalCount
#line default
#line hidden
, 254), false)
);
WriteAttribute("pos", Tuple.Create(" pos=\"", 272), Tuple.Create("\"", 293)
#line 10 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
, Tuple.Create(Tuple.Create("", 278), Tuple.Create<System.Object, System.Int32>(Model.Position
#line default
#line hidden
, 278), false)
);
WriteLiteral(">\r\n <userdata");
WriteLiteral(" name=\"!ViewChanged\"");
WriteLiteral(">");
#line 11 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write((Model.ViewChanged.ToString()));
#line default
#line hidden
WriteLiteral("</userdata>\r\n <userdata");
WriteLiteral(" name=\"!ViewSortColumn\"");
WriteLiteral(">");
#line 12 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write((!string.IsNullOrEmpty(Model.ViewSortColumn) ? Model.ViewSortColumn : ""));
#line default
#line hidden
WriteLiteral("</userdata>\r\n <userdata");
WriteLiteral(" name=\"!ViewSortDirection\"");
WriteLiteral(">");
#line 13 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write((!string.IsNullOrEmpty(Model.ViewSortDirection) ? Model.ViewSortDirection : ""));
#line default
#line hidden
WriteLiteral("</userdata>\r\n <userdata");
WriteLiteral(" name=\"!ViewError\"");
WriteLiteral(">");
#line 14 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write((!string.IsNullOrEmpty(Model.ViewError) ? Model.ViewError : ""));
#line default
#line hidden
WriteLiteral("</userdata>\r\n <userdata");
WriteLiteral(" name=\"!CriteriaError\"");
WriteLiteral(">");
#line 15 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write((!string.IsNullOrEmpty(Model.CriteriaError) ? Model.CriteriaError : ""));
#line default
#line hidden
WriteLiteral("</userdata> \r\n <userdata");
WriteLiteral(" name=\"!FilterError\"");
WriteLiteral(">");
#line 16 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write((!string.IsNullOrEmpty(Model.FilterError) ? Model.FilterError : ""));
#line default
#line hidden
WriteLiteral("</userdata> \r\n");
#line 17 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
#line default
#line hidden
#line 17 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
foreach (DataRow drRow in Model.GenericTableTable.Rows)
{
#line default
#line hidden
WriteLiteral(" <row");
WriteAttribute("id", Tuple.Create(" id=\"", 1074), Tuple.Create("\"", 1116)
#line 19 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
, Tuple.Create(Tuple.Create("", 1079), Tuple.Create<System.Object, System.Int32>(drRow[Model.Table +"^ID"].ToString()
#line default
#line hidden
, 1079), false)
);
WriteLiteral(" RowChangeState=\"0\"");
WriteLiteral(">\r\n");
#line 20 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
#line default
#line hidden
#line 20 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
foreach (PSIMColumn oPSIMColumn in Model.GenericTableDataColumns.AllColumns)
{
switch (oPSIMColumn.PSIMTable.Name.ToUpper())
{
case "MOC":
#line default
#line hidden
WriteLiteral(" <cell />\r\n");
#line 26 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
break;
default:
#line default
#line hidden
WriteLiteral(" <cell ");
#line 28 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write(MvcHtmlString.Create(Model.GetCellAttributes(oPSIMColumn, drRow)));
#line default
#line hidden
WriteLiteral("><![CDATA[");
#line 28 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
Write(Html.Raw(Model.CellValue(oPSIMColumn, drRow)));
#line default
#line hidden
WriteLiteral("]]></cell>\r\n");
#line 29 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
break;
}
}
#line default
#line hidden
WriteLiteral(" </row>\r\n");
#line 33 "..\..\Areas\Views\GenericTable\DataCurrent.cshtml"
}
#line default
#line hidden
WriteLiteral("</rows>\r\n");
}
}
}
#pragma warning restore 1591
答案 0 :(得分:0)
解决此问题的方法可以在https://github.com/RazorGenerator/RazorGenerator/issues/94#issuecomment-220097861找到,它似乎根植于版本差异问题。在将解决方案移至mvc 4和网页2之后,似乎工作正常。在所有项目中擦除所有引用和web.config文件,以确保它们排列,卸载并重新安装所有nuGet包。我也在项目中直接使用源代码,而不是作为nuGet的dll安装,因为从nuGet安装时似乎存在一些版本不匹配。我将这个解决方案放在这里以防其他人遇到与我相同的问题。