[英]Visual Studio 2022/dotnet build: Build and copy dependencies without project reference
My question is similar to Visual studio project build dependencies with no references?我的问题类似于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.我有一个 Web API 项目,它引用了 same.sln 文件中其他项目的一些服务。 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.我希望将他们的 output (DependencyA.dll, DependencyB.dll) 复制到我的 Web API output 文件夹中,但我不想添加项目引用,因为我正在使用依赖注入,所以我什么都不想服务接口可用于 Web API 项目。
How can I make sure:我怎样才能确定:
do.net 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 do.net build
for the.sln file?这也适用于do.net build
,因为这是我们在 TeamCity 中使用的(一个额外的 PowerShell 脚本用于复制文件就可以了)——我想它应该总是有效,只要我们运行do.net build
。 .sln 文件是什么?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?有没有比adding.sln-level project dependencies 和 post-build task for Web API project copy dependencies 更好的方案?
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:我认为在 Web Api 项目中添加构建依赖项并在其他项目中使用构建后事件复制 .dll 文件的解决方案足以解决您的问题:
1. Create project dependencies in the solution . 1. 在解决方案中创建项目依赖。
2.Add post build event in the other projects like this: 2.在其他项目中添加构建后事件,如下所示:
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.当我们在visual studio中构建工程时,它会调用MSBuild。MSBuild指的是.proj文件和工程相关的一些配置文件。 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.所以如果要在主工程(Web Api工程)中调用或使用一些dll/assembly文件(DependencyA.dll、DependencyB.dll),需要在.proj文件或配置文件中设置相关的引用/依赖。 Otherwise VS or MSBuild cannot find and use them.否则VS或MSBuild无法找到并使用。
I don't think there is a better solution about this problem.我不认为这个问题有更好的解决方案。 If anyone have a good solution can share it here.如果有人有好的解决方案可以在这里分享。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.