11

I'm trying to automate deploying a Web Api 2 project with Visual Studio 2013. I've made a publish profile named "Test" shown below

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

Even though it has the line <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> it seems like Visual Studio is publishing my debug build. I'm calling msbuild like so

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

1 Answer 1

13

This excellent blog post led me to find the answer https://sedodream.com/2012/10/27/msbuild-how-to-set-the-configuration-property . I'll summarize in case the link dies: when a build is kicked off MsBuild evaluates the properties once and uses that value for the remainder of the build. Since the Configuration property was resolving to Debug MsBuild was using that as the Configuration to publish.

TLDR;

Pass the configuration on the command line, add

/p:Configuration=Release

to the command line call

6
  • 5
    The <LastUsedBuildConfiguration> element is used by Visual Studio to set the build configuration before launching a build & publish within the IDE. But on the command line, you do have to specify it manually.
    – Jimmy
    Commented Jul 1, 2015 at 17:32
  • Correct, it's just for the Visual Studio UI. That's why we named it LastUsedBuildConfiguration instead of Configuration :) Commented Jul 2, 2015 at 9:09
  • 1
    @SayedIbrahimHashimi A comment at the top of the publish profile detailing this quirk would have saved me a lot of time, please consider adding it Commented Jul 2, 2015 at 14:56
  • @reggaeguitar I thought there was a link pointing to more info about how to automate publishing, which includes that info and more. Commented Jul 2, 2015 at 19:28
  • @SayedIbrahimHashimi I did read that webpage but it wasn't clear that I had to pass in the Configuration property. Thanks for actually responding though, I've seen you on some MVA courses and really like your manner of teaching. Commented Jul 2, 2015 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.