visual-studio 在 Visual Studio 中处理多个项目/解决方案的最佳方式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3383778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to work with multiple projects / solutions in Visual Studio?
提问by Wil
Currently I have 4 solutions that are independent projects, however there is quite a bit of duplicated code when it comes to a few areas of the applications.
目前我有 4 个独立项目的解决方案,但是当涉及到应用程序的几个领域时,有相当多的重复代码。
At the moment it is simply a few forms and their associated code.
目前它只是一些表单及其相关代码。
When I want to change or improve something, I have to copy and paste to all relevant projects.
当我想改变或改进某事时,我必须复制并粘贴到所有相关项目中。
I looked at creating a new project within one of the solutions for the .dll/class library, but I felt that this was incorrect. (Please say if I am wrong).
我看着在 .dll/class 库的解决方案之一中创建一个新项目,但我觉得这是不正确的。(如果我错了,请说)。
As it is a component for all the applications, I decided to create a new solution for the .dll/class library and am looking at moving the shared code over to that - but, having never gone down this route before, what are my options from here?
由于它是所有应用程序的一个组件,我决定为 .dll/class 库创建一个新的解决方案,我正在考虑将共享代码移到那个位置 - 但是,以前从未走这条路,我的选择是什么从这里?
Am I able to then include this solution within the others if I need to make a simple change and have it updated in all the projects or instead, should I always be working on the shared component in a separate instance of Visual Studio, outside of the applications using it?
如果我需要进行简单的更改并在所有项目中更新它,或者我是否应该始终在 Visual Studio 的单独实例中处理共享组件,而不是在应用程序使用它?
采纳答案by pdr
That's exactly the right way to handle this situation.
这正是处理这种情况的正确方法。
You can include projects in multiple solutions by right-clicking the solution and selecting Add Existing Project...
您可以通过右键单击解决方案并选择添加现有项目...
Any changes you then make will appear in all solutions. The only problem this leads to is that it's possible to break one solution from another. This is where automated builds on commit to source control come into their own.
您随后所做的任何更改都将出现在所有解决方案中。这导致的唯一问题是有可能将一个解决方案与另一个解决方案分开。这就是在提交到源代码控制时自动构建的地方。
回答by Afshar Mohebbi
- Put shared codes in separate Solution/Project as Class Library,
- In post build event of shared projects copy dll's to a specific directory,
- Add shared dll's from this directory to other projects/solutions
- 将共享代码作为类库放在单独的解决方案/项目中,
- 在共享项目的后期构建事件中,将 dll 复制到特定目录,
- 将此目录中的共享 dll 添加到其他项目/解决方案
By doing this each time you build your consumer projects, they will use latest dll's automatically.
通过在每次构建消费者项目时执行此操作,它们将自动使用最新的 dll。
回答by slugster
Moving the common code into a separate shared assembly is an excellent option.
将公共代码移动到单独的共享程序集中是一个很好的选择。
One thing to think about is to keep your common business logic or business object type code separate from UI related code like custom controls - if you need to then have two common assemblies. This is more work initially, but makes things way easier further down the track when you need to make UI changes or change the control suite you are using.
要考虑的一件事是将您的通用业务逻辑或业务对象类型代码与 UI 相关代码(如自定义控件)分开 - 如果您需要然后拥有两个通用程序集。这最初需要做更多的工作,但是当您需要更改 UI 或更改您正在使用的控件套件时,会使事情变得更容易。

