Execute MSBuild target on specific project but not on build dependencies

Torben Jonas 1 Reputation point
2022-05-06T09:25:00.587+00:00

I'm trying to publish a project from a .NET Framework 4.8 solution using MsBuild 17.1.0.7609 shipped with Visual Studio 2022.

I try to invoke the "MsDeployPublish" target using this command:

MSBuild.exe .\MySolution.sln /t:"SampleProject:MsDeployPublish" /p:PublishProfile="sampleprofile" /p:UserName='username' /p:Password="secretpassword" /p:DeploymentSlot="TargetSlot" /p:MSDeployServiceURL="ServiceUrl"

The project in question has several projects defined as build dependencies so when building SampleProject these dependencies shall be built too.
Unfortunately it seems that MsBuild tries to execute the MsDeployPublish target on those build dependencies too which I would like to avoid as I get many errors like the following

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\Web\Microsoft.Web.Publishing.targets(4189,5): error MSB4044: The "ConcatFullServiceUrlWithSiteName" task was not given a value for the required parameter "SiteAppName".

Whenever I try to publish this project using Visual Studio's publishing functionality with the same publishing profile the whole process works without any error.

Is there a way to call the MsDeployPublish target just on SampleProject but not on its build dependencies while preserving the behaviour that those build dependencies still get built?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,150 questions
{count} votes