简体   繁体   English

ASP.NET Web项目(C#)是否有按需编译选项?

[英]Is there a compile on demand option for an ASP.NET Web Project (C#)?

I just started working with an ASP.NET application that has been converted from a VB.NET web site to a C# web project and I am finding that my development time is significantly longer using C# than VB.NET. 我刚刚开始使用从VB.NET网站转换为C#Web项目的ASP.NET应用程序,发现使用C#的开发时间比使用VB.NET的开发时间长得多。

When I am editing a simple line of code in an C# code behind file, I have to manually recompile the entire site just to see the result of the change. 当我在文件后面的C#代码中编辑简单的代码行时,我必须手动重新编译整个站点才能看到更改的结果。 In with the web site, I could edit a code behind file and then execute it in the browser to see the result of the change without doing a compile (or alternatively, right-click and choose compile page). 在该网站中,我可以编辑文件后面的代码,然后在浏览器中执行该代码以查看更改的结果,而无需进行编译(或者,右键单击并选择编译页面)。

My question is, is there an option somewhere to compile JUST THE ONE PAGE? 我的问题是,是否有一个选项可以编译“仅一页”? If not, is there something that can be done (other than getting more hardware or converting the project back to web site) to speed up the development/debugging process? 如果不是,是否可以做一些事情(除了获得更多的硬件或将项目转换回网站之外)以加快开发/调试过程?

Clarification 澄清度

In a ASP.NET (VB) Web Site project I can make an edit in code-behind, click the save button, then open up a browser and navigate to the page to instantly see the change (or at least within 5 seconds). 在ASP.NET(VB)网站项目中,我可以在代码隐藏中进行编辑,单击“保存”按钮,然后打开浏览器并导航到页面以立即查看更改(或至少在5秒钟内)。 In a Web Application Project in ASP.NET (C#), I am finding I have to compile the entire web site to view the live change in a browser (a process that takes upwards of 2 minutes). 在ASP.NET(C#)中的Web应用程序项目中,我发现我必须编译整个网站才能在浏览器中查看实时更改(此过程最多需要2分钟)。

You can build your solution at any time by pressing Ctrl + Shift + B . 您可以随时按Ctrl + Shift + B来构建解决方案。

Right-click and Exclude any projects/folders/files you don't want to include. 右键单击并Exclude您不想包括的任何项目/文件夹/文件。

EDIT : A Web Application Project has to be built in its entirety, but Visual Studio only builds those files which have changed so this shouldn't be too slow for you. 编辑 :必须完整地构建Web应用程序项目,但是Visual Studio仅构建那些已更改的文件,因此这对您来说不会太慢。

In a Web Site Project, Visual Studio completely compiles Web site projects whenever you run or debug any page by default - but - you can change the build project option to compile only the current page on run or debug. 在Web 站点项目中,默认情况下,只要您默认运行或调试任何页面,Visual Studio都会完全编译Web站点项目- 但是 ,您可以更改build project选项以在运行或调试时仅编译当前页面。

在此处输入图片说明

Your .aspx and .ascx should reference their codehind files through CodeFile instead of CodeBehind. 您的.aspx和.ascx应该通过CodeFile而不是CodeBehind引用其代码隐藏文件。 Then the codebehin will be compiled on demand. 然后,代码隐藏将按需编译。

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeFile="myPage.aspx.cs" Inherits="myPage" %>

instead of 代替

<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeBehind="myPage.aspx.cs" Inherits="myPage" %>

There are some drawbacks though : 但是有一些缺点:

  • CodeBehind pages can not use CodeFile controls (but codefile pages can use any kind of controls) CodeBehind页面不能使用CodeFile控件(但是Codefile页面可以使用任何类型的控件)
  • referencing codefile controls is a bit more complicated 引用代码文件控件要复杂一些
  • you will lose sync with the .designer.cs and have to reswitch to codebehind for a second to resync. 您将无法与.designer.cs同步,并且必须重新切换到后台代码才能重新同步。

On the long run, CodeFile will save you a lot of time. 从长远来看,CodeFile将为您节省大量时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM