10

A publish profile to publish a Visual Studio Website can be used from both the Visual Studio 2013 publish dialog, and from the command line MsBuild as explained in this question Using msbuild to execute a File System Publish Profile

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe 
./ProjectRoot/MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=FileSystemDebug

However, I want to get rid of the publish profile completely and do everything from the command line - because I do not want the publish path to be hard-coded in the PublishProfile xml file. How can I specify the same options directly in the command line arguments? I have tried using OutDir instead, but that results in a different behavior than the path specified in the PublishProfile (an extra _PublishedWebsites is appended to my path).

Community
  • 1
  • 1
Ande
  • 491
  • 1
  • 7
  • 22
  • I am now generating a temporary publish profile xml file as part of my build script, and deleting it after MSBuild has run. I am not sure if there is a solution to my original question, but this is an easy workaround. – Ande Dec 07 '15 at 13:34

2 Answers2

13

You can actually override the PublishProfile settings from the command line. You would want this parameter:

/p:publishUrl=pathToPublishHere

If it's local filesystem this should work just fine.

thismat
  • 2,096
  • 17
  • 24
10

publish.bat

SET PROJECT="D:\Github\MyWebSite.csproj"
SET MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin"
SET PUBLISH_DIRECTORY="C:\MyWebsitePublished"

cd /d %MSBUILD_PATH%
MSBuild %PROJECT%  /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=%PUBLISH_DIRECTORY%

needs a Visual Studio to be installed on server.

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55