简体   繁体   English

Visual Studio 2022/do.net 构建:在没有项目引用的情况下构建和复制依赖项

[英]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:我怎样才能确定:

  1. Hitting F5 in VS 2022 will build the dependencies if necessary and copy them to the startup project's output folder在 VS 2022 中按 F5 将在必要时构建依赖项并将它们复制到启动项目的 output 文件夹中
  2. This will also work with 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.

相关问题 Visual Studio 2022。我可以默认使用“dotnet build”而不是 MSBuild 来构建项目吗? - Visual Studio 2022. Can I build project with `dotnet build` by default instead of MSBuild? 运行 do.net build 时项目引用未解析 - Project reference not resolved when running dotnet build 为什么在Visual Studio中构建和构建dotnet会产生不同的输出? - Why does dotnet build and build in visual studio produce different output? 在Visual Studio项目中本地复制本机依赖项 - Copy native dependencies locally in a Visual Studio project 构建Visual Studio项目而无需访问引用的dll - Build a Visual Studio Project without access to referenced dlls 在 Visual Studio 2022 中针对 .Net Framework 3.5 构建 - Build against .Net Framework 3.5 in Visual Studio 2022 Bamboo CI 构建的 Visual Studio 解决方案,具有构建顺序依赖项 - Bamboo CI build of Visual Studio solution with build order dependencies 更改目标版本时 Visual Studio 2017 dotnet 崩溃 - Visual Studio 2017 dotnet crash when changing target build 构建时,将项目的全部内容复制到另一个项目的文件夹中(Visual Studio 2013) - Copy the entire contents of a project in a folder of another project, when build (Visual Studio 2013) Visual Studio 2008:项目依赖性和构建顺序全部不同步,可用插件吗? - Visual Studio 2008: Project dependencies and build order all out of sync, plugin available?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM