如何自动化 Visual Studio 2017 web 项目发布到文件夹

How to automate Visual Studio 2017 web project publish to folder

我正在尝试创建一个 PowerShell v5 脚本来构建和发布一个 VS2017 WCF Web 服务应用程序(.NET Framework 4),以便我可以在 Bamboo 中自动化它。我有 msbuild 命令可以正确构建,现在我需要使用 FolderProfile 将项目发布到文件夹。

我可以通过右键单击项目并选择发布,然后选择 FolderProfile 来手动成功完成。这会将需要部署到网站的文件放在项目的 bin\Release\PublishOutput 位置。我想在 Powershell 脚本中自动执行该发布操作。

我试过Sayed Hashimi's网站上的推荐,和下面类似(我只是用的VS2017版本15.2,当然把项目名和配置文件替换成我的实际值);

msbuild MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=<profile-name> /p:Password=<insert-password> /p:VisualStudioVersion=15.2 

但这并没有将任何文件放在 bin\Release\PublishOutput 位置。看起来它只是做了一个标准构建。

编辑:

当我 运行 上述命令时,msbuild 在输出中列出了这一行;

DeploymentUnpublishable:
    Skipping unpublishable project.

我已经在 GitHub 上查看了 this post,有些人引用了一个解决方案作为更新到 VS2017 的 v15.2,我已经完成了;

Microsoft Visual Studio Enterprise 2017
Version 15.2 (26430.16) Release

有什么想法吗?

编辑 - 解决方案

@Leo-MSFT 提供了这个解决方案...

msbuild myproject\myproject.vbproj /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml /p:Configuration=Release

这会将文件放入 bin\release\PublishOutput。

我花了好几天时间寻找这个解决方案,我添加了其他 SO 和 GitHub 论坛 post 中建议的各种命令参数,例如 /t:Publish/p:PublishProfileRootFolder/p:VisualStudioVersion=15.2。我删除了那些并只使用上面的行最终创建了我需要的已发布输出。

this did not put any files in the bin\Release\PublishOutput location. It looked like it just did a standard build

我已经用你的命令行重现了这个问题。研究了很久这个问题,我尝试去掉参数“/p:VisualStudioVersion=15.2”,然后用命令行重新发布项目:

msbuild MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile="MyProfile.pubxml"

构建并发布成功,web项目发布到你在MyProfile.pubxml中设置的文件夹中的“<publishUrl>”选项。

所以请尝试在 MSBuild 命令行中删除参数 "/p:VisualStudioVersion",检查它是否适用。

注意:我还为 Visual Studio 2015 创建的项目使用 VisualStudioVersion 测试了该命令行,它工作正常。不确定这是否是 Visual Studio 2017 的问题,我需要确认一下,如果这是 Visual Studio 2017 的问题,我会将此问题发送给 Visual Studio 团队。