简体   繁体   中英

Copy one file from a project's output directory to another project's output directory

Given:
Visual Studio 2019 solution
2.Net Core Projects
Needs to work in Azure Pipelines
Needs to work locally

Goal is to copy a single file from one project's bin to another project's bin. I need it to work on my local machine and in Azure Pipelines.

SolutionFolder  
  Project_1_DotNetCore31  
  Project_2_DotNetCore31  

I would like to copy a single file

From

Project_1_DotNetCore31\bin\Debug\netcoreapp3.1\TargetFile.txt  

To

Project_2_DotNetCore31\bin\Debug\netcoreapp3.1\TargetFile.txt  

I've tried a couple of things:

  1. Post Build Event in Project 2

    copy $(SolutionDir)Project_1_DotNetCore31\$(outputDir)TargetFile.txt $(outputDir)

This works locally on my development machine but not in Azure Pipelines. $(SolutionDir) becomes undefined.

  1. Post Build Event in Project 2

    copy "..\..\..\..\Project1\bin\$(ConfigurationName)\netcoreapp3.1\TargetFile.txt TargetFile.txt

This didn't work work locally or in Azure DevOps but if I paste it into a command prompt it works fine.

  1. I looked into Azure Copy Files task and I don't understand it.

Looking for suggestions, would like to learn how to use Azure Copy Files task

Try xcopy. I had something like below as post build event of project 1. Did not test with Azure Pipelines though.

xcopy "$(TargetDir)TargetFile.txt" "$(SolutionDir)EvenHubListener\$(OutDir)"

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