[英]How to deploy an ASP.NET MVC application on build using MSBuild in Visual Studio 2015?
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. 这应该产生一个可用于导入IIS的zip文件。 How can I achieve this? 我该如何实现?
Command line 命令行
msbuild yoursolutionfile.sln /p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:PackageLocation="yourpath\yourfilename.zip"
DeployOnBuild tells msbuild to deploy (to package location) DeployOnBuild告诉msbuild部署(到包位置)
WebPublishMethod Creates a deployment package. WebPublishMethod创建部署程序包。 You can choose other options for web publish like file copy. 您可以选择其他网站发布选项,例如文件复制。
PackageAsSingleFile zips the output PackageAsSingleFile压缩输出
Above is all ran at the command line and while not in VS to do it, does build and deploy in one step. 以上都是在命令行中运行的,虽然不是在VS中执行的,但它一步一步构建和部署。 You could have a command window open where you run this command whenever you want to. 您可能会打开一个命令窗口,您可以随时在其中运行此命令。
IN VS VS
You can use the Web Deployment Publish Wizard in VS. 您可以在VS中使用Web部署发布向导 。 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. 但是,这仅在构建发生之后,并且是第二步。
To do it all at once, well, web publish on build via VS is not "supported". 要一次完成所有操作,那么不“支持”通过VS在构建上进行Web发布。 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. 您可以运行我在后期构建中显示的cmd,但这从字面上意味着第二次重新编译,我认为这是一个可怕的想法,因此,除非这不是一个非常小的项目,否则不要这样做,即使那样,不,好的。
In VS in one step 在VS中一步
Back to MSBUILD but with changing the project file's xml (msbuild commands). 返回MSBUILD,但更改项目文件的xml(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. 这实质上是从我的第一个示例创建msbuild的设置,但将其保存到文件中。
Then edit your project file (csproj) as described by @richardSzalay or @chief7 然后按照@richardSzalay或@ chief7所述编辑项目文件(csproj)
The csproj file is the msbuild commands that VS uses. csproj文件是VS使用的msbuild命令。 In those examples, you create some properties (propertygroup) to setup the deployment and an AfterBuild target to run the publish. 在这些示例中,您将创建一些属性(属性组)来设置部署,并创建AfterBuild目标来运行发布。
Find the below property groups from the csproj: 从csproj中找到以下属性组:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
First one is for debug and the second for release. 第一个用于调试,第二个用于发布。
Add the following inside both property groups (If you want the auto build to happen in both debug and release mode). 在两个属性组中添加以下内容(如果希望自动构建同时在调试和发布模式下进行)。
<DeployOnBuild>true</DeployOnBuild>
<PublishProfile>EMRFHIRServer</PublishProfile>
It will now auto publish for both Visual studio build and MSBuild. 现在,它将针对Visual Studio构建和MSBuild自动发布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.