Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MsBuild publish website without using publish profile

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

like image 961
Ande Avatar asked Nov 16 '15 16:11

Ande


People also ask

How do I publish with MSBuild?

You can pass /p:PublishUrl="newpath" to the msbuild command. You would also see this set in the csproj file which you can change.

What is publish profile in MSBuild?

A publish profile is just an MSBuild file. When you pass in PublishProfile and DeployOnBuild=true, then the publish profile is Imported into the build/publish process. It will supply the publish properties needed to perform the publish. Let's see how that works.

Where is publish profile stored?

Publish profile files are named <profilename>. pubxml and are located in the PublishProfiles folder. The PublishProfiles folder is under Properties in a C# web application project, under My Project in a VB web application project, or under App_Data in a web site project.

How do I publish a Visual Studio solution from the command line?

Basic command-line publishingThe default publish folder format is bin\Debug\{TARGET FRAMEWORK MONIKER}\publish\. For example, bin\Debug\netcoreapp2. 2\publish\. The dotnet publish command calls MSBuild, which invokes the Publish target.


1 Answers

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.

like image 83
Alper Ebicoglu Avatar answered Jan 11 '23 11:01

Alper Ebicoglu