msbuildazure-devops

MSBuild Exclude Project when DeployOnBuild flag is set to true


I have the following msbuild arguments:

/m /p:DeployOnBuild=true;PublishProfile="$(PublishProfile).pubxml"

I've added a project that is a shared .NET Web Application that should not be deployed, and does not need publish profiles. However when my build agent runs, it fails because my project does not have publish profiles.

Is there a way to exclude a project or somehow work around this without having to specify individual projects to include?


Solution

  • Is there a way to exclude a project or somehow work around this without having to specify individual projects to include?

    AFAIK, I am afraid there is no such way or property we could exclude a project to be deployed on the Azure DevOps directly.

    If you do not want to specify individual projects to include.

    As a workaround, you could define the property DeployOnBuild in the projects that you want to publish, and pass a value to the property in msbuild arguments to make only this(those) project(s) can be built.

    Details:

    Edited project(s) which you want to publish and added the following property group before the Import statements in the .csproj file:

    <PropertyGroup>
      <DeployOnBuild Condition=" '$(DeployProjOrNot)'!='' ">$(DeployProjOrNot)</DeployOnBuild>
    </PropertyGroup>
    

    Then the msbuild arguments:

    /m /p:DeployProjOrNot=true /p:PublishProfile="$(PublishProfile).pubxml"
    

    In this case, those projects will be published, and the shared .NET Web Application (should not add above Property) will not be published due to the value of the property DeployOnBuild is not set to be true.

    Hope this helps.