如何使Visual Studio的"编译"一个.aspx文件?文件、Studio、Visual、aspx

2023-09-04 13:40:29 作者:外套借她,拥抱给我

在我的ASP.NET MVC应用程序我有一个.aspx文件。我在Visual Studio 2010中项目资源管理器树中选择它,然后转到文件属性 - 在生成操作设置为内容。我改建设行动,以编译,并要求Visual Studio中生成项目。我收到以下错误消息在编译器输出我的.aspx文件:

In my ASP.NET MVC application I have a .aspx file. I select it in Visual Studio 2010 Project Explorer tree and go to file properties - the "Build Action" is set to "Content". I change "Build Action" to "Compile" and ask Visual Studio to build the project. I get the following error message for my .aspx file in the compiler output:

C:\PathToProject\MyFile.aspx(1,1): error CS0234: The type or namespace name 'global_asax'
    does not exist in the namespace 'ASP' (are you missing an assembly reference?)

在.aspx文件的第一行是:

the first line of the .aspx file is:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/My.Master" Inherits="System.Web.Mvc.ViewPage" %>

我不知道这使得...

which makes me wonder...

什么是编译器试图抱怨,我如何让它编译.aspx文件?

What is the compiler trying to complain about and how do I make it compile the .aspx file?

推荐答案

视图的的.aspx必须有其生成操作设置为内容。

The view's .aspx must have its Build Action set to Content.

要启用pre-编译(或者至少,编译器错误检查)在构建时,添加

To enable pre-compilation (or, at least, compiler error checks) at build time, add

    <MvcBuildViews>true</MvcBuildViews>

到第一个&LT;的PropertyGroup>在.csproj的。

to the first <PropertyGroup> in your .csproj.