部署.NET Web应用程序时会发生什么?

时间:2016-10-19 13:19:59

标签: c# iis deployment

我今年改变了工作,因此我从Java切换到C#。在这两个工作中,我在一个大型应用程序上工作/工作,该应用程序部署到服务器并公开各种Web服务。

使用Java作业,ant构建过程创建了一个包含.war文件和其他对象的.ear文件。通过将该文件复制到JBoss / tomcat服务器中的目录中来部署该.ear文件。我对这个过程了如指掌。

通过C#工作,我按下一个绿色三角形"播放"在Visual Studio中按钮,应用程序被编译并以某种方式部署到IIS,然后Visual Studio启动指向应用程序URL的Web浏览器。在此过程中,我并不完全了解幕后发生的事情。我们有一个构建服务器,可以创建生产服务器的生产构建,但我不了解a)构建过程产生了什么工件,以及b)如何将这些构建工件部署到IIS。

我希望能够很好地理解该流程,以便手动驱动构建和部署,重新自动化流程,以及对现有构建和部署流程进行故障排除和修改。我可以使用msbuild驱动构建,但是它产生了什么,以及如何将它部署到另一台机器的IIS安装上?

2 个答案:

答案 0 :(得分:1)

What happens when you hit Run (the green triangle) is probably not the best example, because it is using a specialized form of IIS (sometimes called Cassini) hosted within Visual Studio with a debugger attached.

To get a clearer picture of what happens when deploying, use the Publish tool to deploy to a folder on your desktop. In that folder you will see what is essentially the web root. Your project, minus any code files, and a bin directory with the compiled binaries.

Typically only static files such as html, css, and png, etc. will be deployed, while any code files won't. By default Visual Studio "knows" which files to build into the binary, and which to simply copy to the output folder (and which to ignore). But you can change this in cases where you need to override that behavior, or you have a file type VS doesn't know about. In your solution explorer, right click on a file, select properties. In the properties window for that file you'll see "build action", which shows what VS will do with that file.

Hope that helps.

答案 1 :(得分:1)

只需添加备注。

所以,

如果您正在使用ASP.NET网站,则应该足以手动将其复制到发布文件夹

如果您正在使用ASP.NET Web应用程序,那么在发布之前应该编译它。所有编译操作都由MSBuild - 命令行实用程序执行到buld .net项目。但MSBuild如何理解,应该如何构建以及以何种方式构建?简单 - 有MSBuild指令的特殊文件 - 是解决方案文件(例如如何从命令行"C:\...\MSBuild.exe" /maxcpucount:10 MyAwesomeSolution.sln构建项目)。解决方案文件包含对项目文件的引用(以及项目的构建顺序等),项目文件包含对文件的引用,包括在项目中(以及项目类型 - 库/控制台/ web应用程序/等,框架版本和操作)每个文件 - 构建/内容/资源等)。如果某个文件未包含在项目中,则会被忽略。

因此,当您按绿色按钮时,首先VS将运行MSBuild来构建您的解决方案。应该编写内部解决方案,哪个项目将用作起点,以及在构建之前/之后应该做什么。在项目内部有信息,如何调试项目(通过IIS,IIS表达或smthg其他)。

因此,当我们使用某个CI服务器时,编译我们的解决方案足以在CI服务器上运行MSBuild并提供解决方案的路径。 Ofcource,要通过CI发布已编译的解决方案,应编写其他脚本(到cpy文件等)。

此外,如果您想将网站发布到某个位置,您可以创建"发布个人资料"。它允许您将您的网站发布到IIS,FTP等,但您必须按"发布"手动按钮(右键单击web项目=>发布)

相关问题