Visual Studio. Publish project from command line

40,014

Solution 1

What works best is to add following target to the project file:

<Target Name="AfterBuild">
   <Message Text="Copying to Deployment Dir:" />
   <Copy SourceFiles="@(Content)" DestinationFolder="..\XXX\%(Content.RelativeDir)" />
      <CreateItem Include="$(OutputPath)\*">
        <Output TaskParameter="Include" ItemName="Binaries"/>
      </CreateItem>
   <Copy SourceFiles="@(Binaries)" DestinationFolder="..\XXX\bin" />
</Target>

This way, whenever project got build (from command line or from IDE) it automatically get deployed to specified folder. Thank you everybody for pointing me to right direction.

Solution 2

From ASP.NET Web Deployment using Visual Studio: Command Line Deployment, you can use

msbuild myproject.csproj /p:DeployOnBuild=true /p:PublishProfile=MyPublishProfile

where MyPublishProfile is the profile name that you've already set up somewhere

Solution 3

The /t:publish switch is for ClickOnce applications only, it's not applicable to web projects. Hence the error saying it's unpublishable. :)

Share:
40,014
sha
Author by

sha

During day time - Engineering Manager at the best platform organization (Identity) in the best company in the world (Atlassian). Unleashing potential for every TEAM around the world! Come join us, we're hiring! During weekends - working on my own mobile app (Emojical) - tracking your daily habits and goals in a fun way!

Updated on January 18, 2020

Comments

  • sha
    sha over 4 years

    Is there a way to publish a web project in MS Visual Studio 2010 using CLI? I use DevEnv.exe /Build to build a project and it works fine, but I could not find option to Publish a project.

    One other thing I want to mention. I am trying to publish web project NOT to the IIS directly. I have a location where I publish several projects and then build them automatically into NSIS bundle to be deployed.

  • Salma Bouzid
    Salma Bouzid over 12 years
    Problem I have with this is that it publishes both debug and release modes doesn't it? That could have serious consequences for a live site if your debug config gets published. Think what we need is a CLI batch that does: 'build Release and Publish with this publish setting'.
  • Brian Sweeney
    Brian Sweeney about 10 years
    @RobKent you can set up config file transformations which you can then use to trigger the above behavior only for certain build configurations. Just google .net config transforms.
  • Gusdor
    Gusdor over 8 years
    This is not an answer.
  • Ted Nyberg
    Ted Nyberg almost 8 years
    @Gusdor It was an answer to the OP, as it originally asked why there was an error saying the solution was 'unpublishable'.
  • Auspex
    Auspex almost 6 years
    It wasn't an answer to the OP's question, but a response to his comment on another answer...
  • Toolkit
    Toolkit over 3 years
    Can't find the valid AspnetMergePath
  • Toolkit
    Toolkit over 3 years
    does it tale care of web.config merging?