1

所以我用 nuGet 安装了 RazorGenerator 并添加了 VS 扩展(感谢Visual Studio 找不到自定义工具 RazorGenerator)。

只是为了在我现有的 mvc 应用程序上试用它,我在其中一个视图上将自定义工具更改为 RazorGenerator,并使用右键单击选项“运行自定义工具”生成代码。确实创建了代码。

然后我构建了整个应用程序并尝试运行它,在旧的 razor 脚本和新的预编译代码中设置了一个断点。令我惊讶的是,它仍在运行旧的脚本代码,而不是新的。我是否错过了将执行切换到新代码的步骤。文档有点少,但您会认为如果需要,会提到像这样的重要内容。我知道它使用 WebActivatorEx.PostApplicationStartMethod() 调用 App_Start 中的引导代码,或者至少它这样做了一次,但似乎并没有在每次调试开始时都这样做,即使在 iisreset 之后也是如此。如果我尝试删除源剃须刀视图,则返回结果时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
4

1 回答 1

0

The road to a solution to this issue can be found here https://github.com/RazorGenerator/RazorGenerator/issues/94#issuecomment-220097861, it seems to have been rooted in problems with version discrepancies. Things seem to be working after moving solution to mvc 4 and webpages 2. Scrubbed all references and web.config files in all projects to make sure they lined up, uninstalled and reinstalled all nuGet packages. I am also using the source directly in a project, not installed as a dll from nuGet, since there seemed to be some version mismatch when installing from nuGet. I am placing this solution here in case others run into the same issues as me.

于 2016-05-19T15:38:49.207 回答