0

My question is similar to Visual studio project build dependencies with no references? :

I have a Web API project that references some services from other projects in the same .sln file. I want their output (DependencyA.dll, DependencyB.dll) to be copied to my Web API output folder, but I don't want to add a project reference because I'm using dependency injection, so I don't want anything but the service interfaces to be available to the Web API project.

How can I make sure:

  1. Hitting F5 in VS 2022 will build the dependencies if necessary and copy them to the startup project's output folder
  2. This will also work with dotnet build since that is what we use in TeamCity (an additional PowerShell script for copying the files would be fine) - I guess it should always work, as long as we run dotnet build for the .sln file?

Is there a better solution than adding .sln-level project dependencies and using a post-build task for the Web API project to copy the dependencies over?

TravelingFox
  • 484
  • 5
  • 18

1 Answers1

0

I think the solution to add build dependencies in the Web Api project and use post build event in other projects to copy the .dll files are good enough to your problem:

1.Create project dependencies in the solution.

2.Add post build event in the other projects like this:

xcopy "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)WebApplication1\Output"

What do you want to improve on this method?

When we build project in visual studio, it calls MSBuild. MSBuild refers to the .proj file and some configuration files related to the project. So if you want to call or use some dll/assembly files(DependencyA.dll, DependencyB.dll) in the main project(Web Api project), you need to set relevant references/dependencies in .proj file or configuration file. Otherwise VS or MSBuild cannot find and use them.

I don't think there is a better solution about this problem. If anyone have a good solution can share it here.

Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10