Visual Studio 发布配置文件发布了错误的构建配置

Visual Studio Publish Profile Publishes Wrong Build Configuration

我正在尝试使用 Visual Studio 2013 自动部署 Web Api 2 项目。我制作了一个名为 "Test" 的发布配置文件,如下所示

<?xml version="1.0" encoding="utf-8"?>
    <!--
    This file is used by the publish/package process of your Web project. You can customize the behavior of this process
    by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121. 
    -->
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>x86</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <ExcludeApp_Data>False</ExcludeApp_Data>
        <publishUrl>C:\DbServiceDeploy</publishUrl>
        <DeleteExistingFiles>True</DeleteExistingFiles>
    </PropertyGroup>
    </Project>

尽管它有 Release 行,但似乎 Visual Studio 正在发布我的调试版本。我这样调用 msbuild

    "C:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe" C:\somefolder\Myproj.csproj /p:
DeployOnBuild=true /p:PublishProfile=Test

这个优秀的博客 post 让我找到了答案 http://sedodream.com/2012/10/27/MSBuildHowToSetTheConfigurationProperty.aspx 。我将总结以防 link 死亡:当构建开始时,MsBuild 会评估一次属性并将该值用于构建的其余部分。由于配置 属性 解析为调试 MsBuild 将其用作要发布的配置。

TLDR;

通过命令行配置,添加

/p:配置=发布

到命令行调用