0

I am working with a classic Azure build pipeline which is using the following MsBuild arguments for creating a package and zipping it:

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"

The above arguments are creating an artifact but with too many nested folders. To avoid that I used this argument: based on this SO question: Avoid nested folders in zipped artifact

/p:OutDir="$(build.artifactstagingdirectory)"

which fixed my one problem but now creating another. The build solution task does not create the bin/release folder for some of the projects inside the solution and for that reason some of the copy tasks are failing.

Build solution Task Build solution task

Copy task Batch task

Copy task failing due to missing bin/release MIssing bin release

Copy task working for another project in the solution because bin/release folder exists for it SYnc Project copy task

Nuget task is also failing due to missing bin/release folder enter image description here

Is there any possibility to not miss the bin/release folders when passing /p:OutDir="$(build.artifactstagingdirectory) argument for avoiding nested folders structure for zipped artifact

Capri82
  • 418
  • 6
  • 24

1 Answers1

0

The $(OutDir) property is the Output Directory. This is the location where the project will produce its outputs. The value of $(OutDir) may be bin\Release or bin\Debug (based on the current Configuration) within the project's directory.

Specifying

/p:OutDir="$(build.artifactstagingdirectory)"

is overriding the output directory. The project will produce its outputs in the location given by $(build.artifactstagingdirectory). In your examples, because 'bin\Release' is overridden it won't be created by the project.

Because the output directory was changed, the copy task should be changed to match. i.e. the source for the copy task should be $(build.artifactstagingdirectory).

However, $(build.artifactstagingdirectory) is a variable that only exists in the context of the build pipeline. Overriding $(OutDir) with $(build.artifactstagingdirectory) can only be done within the pipeline which means that for a developer building in Visual Studio the build will behave differently. This discrepancy could cause confusion.

If you are comfortable with MSBuild, you could add a custom target that is dependent on $(build.artifactstagingdirectory) having a value and on the packaging target being run (AfterTargets="AfterPublish"). The project will 'know' its packaging folder which, as an example, might be something like 'bin\Release\publish'. The custom target can copy from 'bin\Release\publish' to $(build.artifactstagingdirectory).

Jonathan Dodds
  • 2,654
  • 1
  • 10
  • 14
  • Hi @Jonathan Dodds your response is much appreciated. Your explanation makes some sense to me and what might be overridden the bin/release folder. Could you please explain more the last part where you are talking about adding the custom target with some example(s) if possible? I would also like to ask based on your explanation, about the bin/release folder being override, why it worked for one project but not for the rest? Any ideas on that? – Capri82 Jul 08 '22 at 09:11