如何在Visual Studio 2015中使用MSBuild在构建上部署ASP.NET MVC应用程序? [英] How to deploy an ASP.NET MVC application on build using MSBuild in Visual Studio 2015?

查看:121
本文介绍了如何在Visual Studio 2015中使用MSBuild在构建上部署ASP.NET MVC应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在构建项目时将应用程序部署到本地文件夹.这应该产生一个可用于导入IIS的zip文件.我该如何实现?

I want the application to be deployed to a local folder when I build the project. This should produce a zip file that I can use to import in IIS. How can I achieve this?

推荐答案

命令行

msbuild yoursolutionfile.sln /p:DeployOnBuild=true 
/p:WebPublishMethod=Package 
/p:PackageAsSingleFile=true 
/p:PackageLocation="yourpath\yourfilename.zip"

DeployOnBuild告诉msbuild部署(到程序包位置)

DeployOnBuild tells msbuild to deploy (to package location)

WebPublishMethod创建一个部署程序包.您可以选择其他网站发布选项,例如文件复制.

WebPublishMethod Creates a deployment package. You can choose other options for web publish like file copy.

PackageAsSingleFile压缩输出

PackageAsSingleFile zips the output

以上都是在命令行中运行的,虽然不是在VS中执行的,但它一步一步构建和部署.您可以打开一个命令窗口,在任何时候都可以在其中运行此命令.

Above is all ran at the command line and while not in VS to do it, does build and deploy in one step. You could have a command window open where you run this command whenever you want to.

与之相对

您可以使用 Web部署VS中的发布向导.在构建"菜单中.它还将引导您完成此步骤.

You can use the Web Deployment Publish Wizard in VS. It's in the Build Menu. It will walk you through the steps for this as well.

但是,这仅是在构建之后才进行的,这是第二步.

However, this is only after the build occurs and is a second step.

要一次完成所有操作,不支持"通过VS在构建上进行Web发布.就像这样,这不是一个简单的方法.您可以运行我在后期构建中显示的cmd,但这实际上意味着第二次重新编译,我认为这是一个可怕的主意,因此,除非这不是一个非常小的项目,否则不要这样做,即使那样,不,也可以.

To do it all at once, well, web publish on build via VS is not "supported". As in, not an easy way to do it. You could run the cmd I showed in the post-build but that literally means a second recompile and I think that's a horrible idea, so don't unless this is a really small project and even then, no, ok maybe.

一步一步在VS中

返回MSBUILD,但更改项目文件的xml(msbuild命令).

Back to MSBUILD but with changing the project file's xml (msbuild commands).

首先创建您的发布配置文件(由发布向导创建的文件).这实质上是从我的第一个示例创建msbuild的设置,但将其保存到文件中.

First create your publish profile (the file created by the publish wizard). This essentially creates the settings for msbuild from my first example but saves it to a file.

然后按照 @ chief7

csproj文件是VS使用的msbuild命令.在这些示例中,您将创建一些属性(属性组)来设置部署,并创建AfterBuild目标来运行发布.

The csproj file is the msbuild commands that VS uses. In those examples, you create some properties (propertygroup) to setup the deployment and an AfterBuild target to run the publish.

这篇关于如何在Visual Studio 2015中使用MSBuild在构建上部署ASP.NET MVC应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆