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

reg*_*tar 8 msbuild visual-studio-2013

我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)

即使它有行<LastUsedBuildConfiguration> Release </ LastUsedBuildConfiguration>,似乎Visual Studio正在发布我的调试版本.我这样叫msbuild

    "C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" C:\somefolder\Myproj.csproj /p:
DeployOnBuild=true /p:PublishProfile=Test
Run Code Online (Sandbox Code Playgroud)

reg*_*tar 9

这篇优秀的博客文章让我找到了答案http://sedodream.com/2012/10/27/MSBuildHowToSetTheConfigurationProperty.aspx.我将总结链接死亡的情况:当一个构建被启动时,MsBuild会对属性进行一次评估,并将该值用于构建的其余部分.由于Configuration属性正在解析为Debug,因此MsBuild使用它作为要发布的配置.

TLDR;

在命令行上传递配置,添加

/ P:配置=推出

到命令行调用

  • Visual Studio使用<LastUsedBuildConfiguration>元素在IDE中启动构建和发布之前设置构建配置.但是在命令行上,您必须手动指定它. (3认同)