MsBuild publish website without using publish profile

11,723

Solution 1

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.

Solution 2

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.

Share:
11,723
Ande
Author by

Ande

Updated on June 15, 2022

Comments

  • Ande
    Ande almost 2 years

    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).

    • Ande
      Ande over 8 years
      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.