使用预编译视图部署 webapp

Deploying webapp with precompiled views

我想使用 web 部署方法将 web 应用程序部署到测试服务器。应用程序正常构建,没有问题,并且在本地和测试服务器上运行良好。当我想在部署期间使用预编译设置时出现问题。在此过程中,我在 VerifyCode.cshtml 文件中遇到了很多错误。问题是我的视图文件夹中甚至没有名为 VerifyCode 的视图。问题出在哪里?我同时使用匿名和 windows 身份验证。

我的发布设置:

我收到的示例错误:

The name 'ViewBag' does not exist in the current context
The name 'Scripts' does not exist in the current context
The name 'Model' does not exist in the current context
'HtmlHelper' does not contain a definition for 'TextBoxFor' ...

等等...

VerifyCode.cshtml代码:

@model App.Models.VerifyCodeViewModel
@{
    ViewBag.Title = "Verify";
}

<h2>@ViewBag.Title.</h2>

@using (Html.BeginForm("VerifyCode", "Account", new { ReturnUrl = Model.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) {
    @Html.AntiForgeryToken()
    @Html.Hidden("provider", @Model.Provider)
    @Html.Hidden("rememberMe", @Model.RememberMe)
    <h4>Enter verification code</h4>
    <hr />
    @Html.ValidationSummary("", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(m => m.Code, new { @class = "col-md-2 control-label" })
        <div class="col-md-10">
            @Html.TextBoxFor(m => m.Code, new { @class = "form-control" })
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <div class="checkbox">
                @Html.CheckBoxFor(m => m.RememberBrowser)
                @Html.LabelFor(m => m.RememberBrowser)
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" class="btn btn-default" value="Submit" />
        </div>
    </div>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

好的,我成功了。问题很简单。我不知道如何,但我在我的项目中随机放置了一个名为 VerifyCode 的视图。

有趣的是,VS 搜索文本工具无法找到它。我做了一些研究,例如here 发现 VS 中的文本搜索存在一些问题,并不总是按预期工作。

因此,在预编译视图时,所有视图文件都与这个没有引用的鬼鬼祟祟的文件拼凑在一起。