简体   繁体   English

在没有Web部署项目的VS中预编译Web应用程序项目?

[英]Precompiling Web Application Project in VS WITHOUT Web Deployment Project?

I want to precompile my entire ASP.NET Web Application Project inside Visual Studio 2010, mainly to make sure there are no errors in the pages and controls. 我想在Visual Studio 2010中预编译我的整个ASP.NET Web应用程序项目,主要是为了确保页面和控件中没有错误。

How can I do this without using a Web Deployment Project? 不使用Web部署项目怎么办? I tried using a WDP, but it has a massively annoying bug that causes it to compile all files in the application folder, including files that have been "excluded." 我尝试使用WDP,但是它有一个令人讨厌的错误,导致它编译应用程序文件夹中的所有文件,包括已被“排除”的文件。 It is maddening. 这太疯狂了。

To be clear, I understand how to compile my application in VS. 明确地说,我了解如何在VS中编译我的应用程序。 I also know how to deploy it. 我也知道如何部署它。 What I want to know here is how to PRECOMPILE the entire application (including all ASPX and ASCX files) BEFORE deployment. 我在这里想知道的是在部署之前如何预编译整个应用程序(包括所有ASPX和ASCX文件)。 This is important to me because it is the only way to make sure there are no errors in the ASPX or ASCX files before runtime. 这对我很重要,因为这是确保运行时之前ASPX或ASCX文件中没有错误的唯一方法。 I understand that there are command-line tools for this. 我了解有为此使用的命令行工具。 I want to precompile inside VS, however, so that I can quickly correct any problems found. 但是,我想在VS中进行预编译,以便可以快速纠正发现的任何问题。

So is there another way to do it? 那么还有另一种方法吗? Is there some way to customize the Publish command? 有一些自定义发布命令的方法吗?

Really appreciate the help, as MS documentation on this subject is frustrating, repetitive, and far-flung. 非常感谢您的帮助,因为与此主题相关的MS文档令人沮丧,重复且冗长。

Brian 布赖恩

Years after the question, but some people might find it useful. 这个问题问了多年,但有些人可能会觉得有用。 I'm using VS 2013, but used this in VS 2010 previously too. 我正在使用VS 2013,但以前也在VS 2010中使用了此功能。

Go to Tool/External Tools, Add button. 
Title: Pre Compile 
Command: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe 
Arguments: -p $(SolutionDir)\Web  -v / 
Initial directory: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ 
[TICK] : Use Output Window

Obviously, change the path to a suitable .net framework. 显然,将路径更改为合适的.net框架。 You can click on the errors and the file opens within VS on the correct line. 您可以单击错误,然后在VS中的正确行上打开文件。 Weird things is that sometimes I run it multiple times and get different outputs... 奇怪的是,有时我会多次运行它并获得不同的输出...

The downside to this is that it doesn't tell you when it's done (you can always check for aspnet_compiler in the task explorer!). 缺点是它不会告诉您完成的时间(您始终可以在任务浏览器中检查aspnet_compiler!)。 So I've done a DOS batch file for the only purpose of saying "done" in the Output window. 因此,我完成了一个DOS批处理文件,其唯一目的是在“输出”窗口中说“完成”。 Note that the command line is different to the above, as in this version I've replicated the command line effectively generated by our own msbuild script (it uses "fixednames" for example to resolve circular references precompiler errors). 请注意,命令行与上述命令行不同,因为在此版本中,我已经复制了由我们自己的msbuild脚本有效生成的命令行(例如,它使用“ fixednames”来解决循环引用预编译器错误)。 The %~f1 is the "argument" input box of the External Tools window from VS. %〜f1是VS的“外部工具”窗口的“参数”输入框。

Batch file (precompile.cmd): 批处理文件(precompile.cmd):

@echo C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -p "%~f1" -v / -f -c -fixednames c:\temp\SomeFolder
@c:
@cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\
@C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -p "%~f1" -v / -f -c -fixednames c:\temp\SomeFolder
@echo.
@echo Done.

In VS: 在VS中:

Go to Tool/External Tools, Add button. 
Title: Pre Compile 2
Command: C:\mypath\precompile.cmd
Arguments: $(SolutionDir)\Web
Initial directory: [leave blank]
[TICK] : Use Output Window

PS: not sure how/if this is affected by Web Sites or Web Applications. PS:不确定如何/是否受到网站或Web应用程序的影响。

So, here's my current solution, which is far from ideal. 因此,这是我当前的解决方案,远非理想。

  1. I created a One-Click Publish profile to publish the application to a local folder on my machine. 我创建了一键发布配置文件,将应用程序发布到计算机上的本地文件夹中。 This local copy of the site can be used an an input to Aspnet_compiler, which does the precompilation. 该站点的本地副本可以用作Aspnet_compiler的输入,该文件将进行预编译。

  2. I created a new build configuration called "Precompile." 我创建了一个名为“ Precompile”的新构建配置。

  3. In the project file, I created a new "Target" that only runs when the Precompile configuration is active (see below for syntax). 在项目文件中,我创建了一个新的“目标”,该目标仅在预编译配置处于活动状态时运行(有关语法,请参见下文)。 This basically tells MSBuild to run an extra task after compilation; 这基本上告诉MSBuild在编译后运行额外的任务。 that is, it will run Aspnet_compiler to precompile the site. 也就是说,它将运行Aspnet_compiler来预编译站点。 It takes the site files generated by One-Click, precompiles them, and outputs them to a second local folder. 它采用一键式生成的站点文件,对其进行预编译,然后将其输出到第二个本地文件夹。 If any errors are found during precompilation, they are displayed in VS. 如果在预编译期间发现任何错误,它们将显示在VS中。

This is a totally half-baked solution with glitches. 这是一个半生不熟的故障解决方案。 The biggest is that any errors found by Aspnet_compiler point to the files in the One-Click folder, so if you double-click on them, they take you to those files, not the solution files. 最大的是,Aspnet_compiler发现的任何错误都指向“一键式”文件夹中的文件,因此,如果双击它们,它们会将您带到这些文件,而不是解决方案文件。

It's nice that I can control precompilation with this method. 我可以用这种方法控制预编译,这很好。 The task does not run unless I select the Precompile configuration. 除非选择“预编译”配置,否则该任务不会运行。 But the whole thing feels roundabout and silly. 但是整个事情感觉很round回。

Maybe a better solution will emerge. 也许会出现一个更好的解决方案。

Here is the element that I added to the project file, at the end, inside the main <Project> element: 这是我最后添加到项目文件中的主<Project>元素内部的元素:

<Target Name="AfterCompile"
     Condition=" '$(Configuration)|$(Platform)' == 'Precompile|AnyCPU' ">

    <AspNetCompiler PhysicalPath="[Source files created by One-click]"
    VirtualPath="/" Force="true"
    TargetPath="[Destination folder]" />
</Target>

Build the solution. 构建解决方案。 Make sure that web application is not excluded from the build, but checking in solutions property pages. 确保该Web应用程序未从构建中排除,而是签入解决方案属性页。

Can't remember whether 'Exclude website while building solution' is for web application project / website project or both. 不记得“在构建解决方案时排除网站”是针对Web应用程序项目/网站项目还是两者都适用。

I have to post another answer as I could not attach the image in the comment. 由于无法在评论中附加图片,因此我必须发布另一个答案。

请参阅构建网站作为解决方案选项的一部分

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

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