简体   繁体   中英

msbuild argument /p:OutDir="$(build.artifactstagingdirectory)" causing some projects to miss "bin/release" folder

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构建解决方案任务

Copy task批处理任务

Copy task failing due to missing bin/release缺少垃圾箱释放

Copy task working for another project in the solution because bin/release folder exists for itSYnc 项目复制任务

Nuget task is also failing due to missing bin/release folder在此处输入图像描述

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

The $(OutDir) property is the Out put Dir ectory. 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. ie 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM