使用的MSBuild,我该如何建立从命令行的MVC4解决方案(在申请的过​​程中Web.config文件的转换),并输出到一个文件夹?我该、命令行、文件夹、解决方案

2023-09-04 01:58:34 作者:国际辣条协会会长

我认为问题标题pretty的不多说了这一切,但为了清楚起见,我想:

构建在命令行(的MSBuild)一个VS2010 ASP.NET MVC4的解决方案,指定的解决方案配置(如发行) 的过程中应用该配置中的任何Web.config文件转换 输出结果到一个文件夹在本地机器上(没有IIS,代理,zip文件,FTP,包等,只是的文件夹的载运行一个网站所需的所有文件)

我一直在试图对SO和一般的谷歌搜索,现在这出了将近一个星期,通过微软的文档(这是壮观无益),其他的答案。我不知道如果我只是没有得到它(这是完全有可能的),或者如果的MSBuild / MSDeploy真的是神秘的混乱目前,它似乎是。

有一个相当简单的方式来实现这一目标?帮助,请!

解决方案

如果您正在运行VS2010:确保你已经安装了Azure的1.7+ SDK(即使你不发布到Azure中,它增加了VS2012发布功能VS2010)

VS2012 +具备这些特色的内置

 的MSBuild ProjectFile.csproj / P:配置=释放^
                           / P:平台=值为anycpu ^
                           / T:WebPublish ^
                           / P:WebPublishMethod =文件系统^
                           / P:DeleteExistingFiles = TRUE ^
                           / P:publishUrl = C:\输出
 

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

 的MSBuild Solution.sln / P:配置=释放^
                     / P:DeployOnBuild = TRUE ^
                     / P:DeployDefaultTarget = WebPublish ^
                     / P:WebPublishMethod =文件系统^
                     / P:DeleteExistingFiles = TRUE ^
                     / P:publishUrl = C:\输出
 

无论哪种方式,您还可以设置 / P:precompileBeforePublish = TRUE ,输出会pcompiled版网站的$ P $

一旦你拥有了Azure的SDK安装你通常会创建一个发布配置文件,并简单地使用 / P:PublishProfile = DeployToFolder ,但我已经给你手动命令行如果你不感兴趣的新的出版的东西去全押。

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

Build a VS2010 ASP.NET MVC4 solution from the command line (MSBuild), specifying a solution configuration (e.g. Release) Apply any Web.config transformations for that configuration during the process 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)

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!

解决方案

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+ 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

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

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.