使用 MSBuild,我如何从命令行构建 MVC4 解决方案(在过程中应用 Web.config 转换)并输出到文件夹?

Using MSBuild, how do I build an MVC4 solution from the command line (applying Web.config transformations in the process) and output to a folder?(使用 MSBuild,我如何从命令行构建 MVC4 解决方案(在过程中应用 Web.config 转换)并输出到文件夹?) -
本文介绍了使用 MSBuild,我如何从命令行构建 MVC4 解决方案(在过程中应用 Web.config 转换)并输出到文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我认为问题标题已经说明了一切,但为了清楚起见,我试图:

I think the question title pretty much said it all, but for clarity, I am trying to:

  1. 从命令行 (MSBuild) 构建 VS2010 ASP.NET MVC4 解决方案,指定解决方案配置(例如发布)
  2. 在此过程中为该配置应用任何 Web.config 转换
  3. 将结果输出到本地机器上的一个文件夹中(没有 IIS、代理、zip 文件、FTP、包等,只是 一个文件夹 包含运行该网站所需的所有文件)
  1. Build a VS2010 ASP.NET MVC4 solution from the command line (MSBuild), specifying a solution configuration (e.g. Release)
  2. Apply any Web.config transformations for that configuration during the process
  3. Output the results into a folder on the local machine (no IIS, agents, zip files, FTP, packages etc, just a folder containing all the files required to run that web site)

我已经尝试通过 Microsoft 文档(非常无用)、关于 SO 和一般谷歌搜索的其他答案来解决这个问题将近一周.我不知道我是否只是没有得到它(这完全有可能),或者 MSBuild/MSDeploy 是否真的是它目前看起来的神秘混乱.

I've been trying to figure this out for almost a week now, through the Microsoft docs (which are spectacularly unhelpful), other answers on SO and general Googling. I don't know if I'm just not getting it (which is entirely possible), or if MSBuild/MSDeploy really is the cryptic mess it currently appears to be.

有没有一种相当简单的方法来实现这一点?请帮忙!

Is there a reasonably simple way to achieve this? Help, please!

推荐答案

如果您运行的是 VS2010:请确保您已安装 Azure 1.7+ SDK(即使您没有发布到 Azure,它也会将 VS2012 发布功能添加到VS2010)

If you are running VS2010: ensure you have the Azure 1.7+ SDK installed (even if you're not publishing to Azure, it adds the VS2012 publishing features to VS2010)

VS2012+ 内置了这些功能

VS2012+ have these featured built in

msbuild ProjectFile.csproj /p:Configuration=Release ^
                           /p:Platform=AnyCPU ^
                           /t:WebPublish ^
                           /p:WebPublishMethod=FileSystem ^
                           /p:DeleteExistingFiles=True ^
                           /p:publishUrl=c:output

或者,如果您正在构建解决方案文件:

Or if you are building the solution file:

msbuild Solution.sln /p:Configuration=Release ^ 
                     /p:DeployOnBuild=True ^
                     /p:DeployDefaultTarget=WebPublish ^
                     /p:WebPublishMethod=FileSystem ^
                     /p:DeleteExistingFiles=True ^
                     /p:publishUrl=c:output

无论哪种方式,您也可以设置 /p:PrecompileBeforePublish=true 并且输出将是网站的预编译版本.

Either way, you can also set /p:PrecompileBeforePublish=true and the output will be a precompiled version of the site.

安装 Azure SDK 后,您通常会创建一个发布配置文件并简单地使用 /p:PublishProfile=DeployToFolder 但我已经为您提供了手动命令行以防您不感兴趣全力投入新的出版内容.

Once you have the Azure SDK installed you would usually create a publish profile and simply use /p:PublishProfile=DeployToFolder but I've given you the manual command line in case you're not interested in going all-in with the new publishing stuff.

这篇关于使用 MSBuild,我如何从命令行构建 MVC4 解决方案(在过程中应用 Web.config 转换)并输出到文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)