RazorGenerator 生成的代码没有执行,脚本代码仍然是
Code generated by RazorGenerator not executed, script code still is
所以我安装了带有 nuGet 的 RazorGenerator 并添加了 VS 扩展(感谢 Visual Studio cannot find custom tool RazorGenerator)。
为了在我现有的 mvc 应用程序上进行尝试,我在其中一个视图上将自定义工具更改为 RazorGenerator,并使用右键单击选项生成代码 "Run Custom Tool"。确实创建了代码。
然后我构建了整个应用程序并尝试 运行 它,在旧的 razor 脚本和新的预编译代码中设置断点。令我惊讶的是,它仍然是 运行 旧的脚本代码,而不是新的。我是否错过了将执行切换到新代码的某个步骤。文档有点简陋,但你会认为如果需要的话,会提到像这样重要的东西。我知道它使用 WebActivatorEx.PostApplicationStartMethod() 调用 App_Start 中的 bootstrap 代码,或者至少它这样做了一次,但似乎并没有在每次调试开始时都这样做,甚至在之后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
可以在此处找到解决此问题的途径https://github.com/RazorGenerator/RazorGenerator/issues/94#issuecomment-220097861,它似乎是版本差异问题的根源。将解决方案移动到 mvc 4 和网页 2 后,一切似乎都在工作。清理所有项目中的所有引用和 web.config 文件,以确保它们排列、卸载并重新安装所有 nuGet 包。我也在项目中直接使用源代码,而不是从 nuGet 安装为 dll,因为从 nuGet 安装时似乎存在一些版本不匹配。我将此解决方案放在这里以防其他人 运行 遇到与我相同的问题。
所以我安装了带有 nuGet 的 RazorGenerator 并添加了 VS 扩展(感谢 Visual Studio cannot find custom tool RazorGenerator)。
为了在我现有的 mvc 应用程序上进行尝试,我在其中一个视图上将自定义工具更改为 RazorGenerator,并使用右键单击选项生成代码 "Run Custom Tool"。确实创建了代码。
然后我构建了整个应用程序并尝试 运行 它,在旧的 razor 脚本和新的预编译代码中设置断点。令我惊讶的是,它仍然是 运行 旧的脚本代码,而不是新的。我是否错过了将执行切换到新代码的某个步骤。文档有点简陋,但你会认为如果需要的话,会提到像这样重要的东西。我知道它使用 WebActivatorEx.PostApplicationStartMethod() 调用 App_Start 中的 bootstrap 代码,或者至少它这样做了一次,但似乎并没有在每次调试开始时都这样做,甚至在之后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
可以在此处找到解决此问题的途径https://github.com/RazorGenerator/RazorGenerator/issues/94#issuecomment-220097861,它似乎是版本差异问题的根源。将解决方案移动到 mvc 4 和网页 2 后,一切似乎都在工作。清理所有项目中的所有引用和 web.config 文件,以确保它们排列、卸载并重新安装所有 nuGet 包。我也在项目中直接使用源代码,而不是从 nuGet 安装为 dll,因为从 nuGet 安装时似乎存在一些版本不匹配。我将此解决方案放在这里以防其他人 运行 遇到与我相同的问题。