We have one ASP.Net solution with several projects. each project have build.pubxml
with unique folder path.
For example:
In project Test
we have this line inside the build.pubxml
:
<publishUrl>C:\publish\SolutionName\Test</publishUrl>
In project Exam
we have this line inside the build.pubxml
:
<publishUrl>C:\publish\SolutionName\Exam</publishUrl>
In the build pipeline (in TFS) with have MSBuild step with this argument:
/p:PublishProfile=build.pubxml
After the build we got 2 folders - Test
and Exam
in C:\publish\SolutionName
.
So far so good.
The problem is we have few branches, and we want to separate the publish folder for each branch, so we added .pubxml
for each branch and in the build pipeline we specified the correct one. but is make are a lot of work on each new branch created and can cause mistakes.
We tried to pass the /p:publishUrl=C:\publish\BranchName
in the MSBuild but then we got a one folder with all the content of Test
and Exam
and not two folders.
The idea is to have only one .pubxml
file for each project with a parameter and pass the value in the pipeline, for example:
<publishUrl>C:\publish\$(Parameter)\Test</publishUrl>
And in the build we will pass the parameter according to the branch.
It is possible to do something like this?
It is possible to do something like this?
The answer is Yes. Since msbuild accepts Global Properties in command-line. If we define one Property in build.pubxml
like <publishUrl>C:\PublishFolders\$(BranchID)\xxx(Test,Exam...)</publishUrl>
, then we can simply pass the value in msbuild arguments like this:
Then we'll get Test
and Exam
folders under C:\PublishFolders\NewTest
. Also we can choose to pass the pipeline predefined variables to the command like: /p:BranchID=$(Build.SourceBranch)
...
This works for build in local machine, tfs and Azure Devops pipeline. Hope all above helps :)