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

11

我正在尝试使用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>

尽管它有行 <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
1个回答

13
这篇优秀的博客文章帮助我找到了答案https://sedodream.com/2012/10/27/msbuild-how-to-set-the-configuration-property。如果链接失效,我会总结一下:当启动构建时,MsBuild会评估属性一次,并在整个构建过程中使用该值。由于Configuration属性解析为Debug,MsBuild将其用作发布的配置。

简而言之:

通过命令行传递配置,添加

/p:Configuration=Release

到命令行调用中。


5
<LastUsedBuildConfiguration> 元素用于在Visual Studio中设置构建配置,以在IDE内启动构建和发布。但是在命令行中,您必须手动指定它。 - Jimmy
没错,它只是为了Visual Studio的用户界面。这就是为什么我们将其命名为LastUsedBuildConfiguration而不是Configuration的原因 :) - Sayed Ibrahim Hashimi
1
@SayedIbrahimHashimi 如果在发布配置文件的顶部添加一个详细说明这个怪癖的注释,那么可以节省我很多时间,请考虑添加它。 - reggaeguitar
@reggaeguitar 我认为有一个链接指向更多关于如何自动发布的信息,其中包括该信息和更多内容。 - Sayed Ibrahim Hashimi
@SayedIbrahimHashimi,我确实阅读了那个网页,但它并没有明确指出我必须传递 Configuration 属性。不过还是谢谢您的回复,我在一些 MVA 课程中见过你,非常喜欢你的教学方式。 - reggaeguitar
@SayedIbrahimHashimi 我在VS2015中创建了一个发布配置文件,我们创建了一个名为“ReleaseX64”的配置来构建64位DLL,我已经选择了“ReleaseX64”作为我的发布配置文件。当我从VS2015发布时,一切都很顺利,但是当我使用命令行时,它会发布Debug / x86 DLL。 msbuild myProj.csproj /p:VisualStudioVersion=14.0 /p:DeployOnBuild=true /p:PublishProfile=<profile-name> 我尝试传递/p:Configuration=ReleaseX64,但它给出了错误,说配置不存在,有人可以帮助我吗? - Ashwath

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接