40

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.

sha
  • 17,706
  • 5
  • 61
  • 98

3 Answers3

48

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

KyleMit
  • 35,223
  • 60
  • 418
  • 600
dten
  • 2,324
  • 21
  • 28
29

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.

KyleMit
  • 35,223
  • 60
  • 418
  • 600
sha
  • 17,706
  • 5
  • 61
  • 98
  • 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'. – Rob Kent Jan 13 '12 at 17:01
  • 1
    @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. – Brian Sweeney Jun 13 '14 at 13:45
  • does it tale care of web.config merging? – Toolkit Jan 10 '21 at 12:39
6

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

Ted Nyberg
  • 6,188
  • 7
  • 38
  • 65