I have a C# dll that I am using in several C# projects. If I update the dll I have to rebuild all the projects manualy. How can I automate this?

huangapple go评论64阅读模式
英文:

I have a C# dll that I am using in several C# projects. If I update the dll I have to rebuild all the projects manualy. How can I automate this?

问题

  1. 可以在 DLL 中编写一些代码,使其在构建时自动构建所有相关的项目吗?
  2. 如果 1) 不可行,是否可以使用单独的 C# 项目或 PowerShell 脚本来实现自动化?
英文:

I have a C# dll (VS 2022) that I am using in several C# projects (VS 2022). If I update the dll I have to rebuild all the related projects manually.

  1. Is it possible to program something in the dll that when I build it, all the related projects are built automatically

  2. If 1) is not possible, can I make this automation with a separate C# project or powershell script?

答案1

得分: 2

使用Visual Studio,假设DLL和DLL的消费者的所有源代码都在同一个源代码控制仓库中:

  • 创建一个解决方案(.sln)
  • 将所有项目添加到解决方案中,包括DLL项目和依赖于DLL的项目
  • 在依赖于DLL的项目中,将DLL项目添加为项目引用

构建解决方案或构建解决方案中的特定项目将检查依赖项。

英文:

With Visual Studio and assuming all the source code for the DLL and the consumers of the DLL is in the same source control repo:

  • Create a solution (.sln)
  • Add all the projects to the solution, including the DLL project and the projects that depend on the DLL
  • In the projects that depend on the DLL, add a project reference to the DLL project

Building the solution or building a specific project within the solution will check dependencies.

答案2

得分: 1

我测试了两种方法:

  1. 将 DLL 项目和依赖于 DLL 的项目放入一个解决方案中,然后添加 构建依赖项。这可以确保在编译依赖项目时,依赖项目会首先进行编译。

  2. 如Jonathan所说,您需要添加项目引用,这样在编译引用的项目时,当前项目会自动更新。

还有另一种方式:如果您使用 浏览 的方式来添加引用,例如,将 DLL 放入一个文件夹,然后导入到项目中。

您可以向您的 DLL 项目添加一个后期构建事件

del $(SolutionDir)ConsoleApp1\ClassLibrary1.dll & xcopy /y $(TargetPath) $(SolutionDir)ConsoleApp1\ 

在构建 DLL 后,您可以自动更新目标地址的 DLL。

英文:

I tested two methods

Put the Dll project and the Dll-dependent project into a solution, add Build Dependencies. This ensures that when compiling dependent projects, the dependent projects are compiled first.

What you need is as Jonathan said: add project references, which can automatically update the current project when compiling the referenced project.

There is another way: if the way you add references is by using browse. For example, put the dll in a folder and import it into the project.

You can add a post-build event to your dll project:

del $(SolutionDir)ConsoleApp1\ClassLibrary1.dll & xcopy /y $(TargetPath) $(SolutionDir)ConsoleApp1\

After you build the dll, you can automatically update the dll of the target address.

huangapple
  • 本文由 发表于 2023年2月27日 19:41:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75580021.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定