Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate Visual Studio 2017 web project publish to folder

I am trying to create a PowerShell v5 script to build and publish a VS2017 WCF Web Service Application (.NET Framework 4) so that I can automate it in Bamboo. I have the msbuild command working that does the build correctly and now I need to publish the project to a folder using a FolderProfile.

I can do it manually with success by right-clicking on the project and selecting publish, then selecting the FolderProfile. This puts the files that need to be deployed to the website in the project's bin\Release\PublishOutput location. I want to automate that publishaction in a Powershell script.

I have tried the recommendation on Sayed Hashimi's site, which is similar to below (I just use VS2017 version of 15.2, and, of course, replace the project name and profile with my actual values);

msbuild MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=<profile-name> /p:Password=<insert-password> /p:VisualStudioVersion=15.2 

But this did not put any files in the bin\Release\PublishOutput location. It looked like it just did a standard build.

EDIT:

msbuild lists this line in the output when I run the above command;

DeploymentUnpublishable:
    Skipping unpublishable project.

I have looked through this post on GitHub and some have cited a solution as updating to v15.2 of VS2017, which I have already done;

Microsoft Visual Studio Enterprise 2017
Version 15.2 (26430.16) Release

Any Ideas?

EDIT - Solution

@Leo-MSFT provided this solution...

msbuild myproject\myproject.vbproj /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml /p:Configuration=Release

This put the files into bin\release\PublishOutput.

I had spent several days searching for this solution and I had added various command parameters suggested in other SO and GitHub forum posts, such as /t:Publish, /p:PublishProfileRootFolder and /p:VisualStudioVersion=15.2. I removed those and just used the line above which finally created the published output I needed.

like image 380
EiEiGuy Avatar asked Jul 28 '17 16:07

EiEiGuy


People also ask

What command does Visual Studio use to publish?

Basic command-line publishing The 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.

How do I publish a Visual Studio project to a server?

On the computer where you have the ASP.NET project open in Visual Studio, right-click the project in Solution Explorer, and choose Publish. If you have previously configured any publishing profiles, the Publish pane appears. Click New or Create new profile.

How do I publish a Visual Studio Web app?

In Solution Explorer, right-click your project and choose Publish. If you're publishing this web app for the first time, next you see the Publish wizard. Visual Studio filters the list of destinations depending on the type of web app.

How do I publish a solution in Visual Studio 2017?

Publish the app Make sure that Visual Studio is using the Release build configuration. If necessary, change the build configuration setting on the toolbar from Debug to Release. Right-click on the HelloWorld project (not the HelloWorld solution) and select Publish from the menu.


1 Answers

this did not put any files in the bin\Release\PublishOutput location. It looked like it just did a standard build

I have reproduced this issue with your command line. After research this issue for a long time, I try to remove the parameter "/p:VisualStudioVersion=15.2", then re-publish the project with the command line:

msbuild MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile="MyProfile.pubxml"

It build and publish successfully, and web project publish to folder where you set in the option "<publishUrl>" in MyProfile.pubxml.

So please try to remove the parameter "/p:VisualStudioVersion" in the MSBuild command line, check if it works for you.

Note: I have also test that command line with VisualStudioVersion for the project created by the Visual Studio 2015, it works fine. Not sure whether this is a issue for Visual Studio 2017, I need to confirm it, if it`s a issue for Visual Studio 2017, I will send this issue to Visual Studio team.

like image 83
Leo Liu-MSFT Avatar answered Oct 09 '22 02:10

Leo Liu-MSFT