简体   繁体   English

C#如何创建具有多个相同命名项目的解决方案?

[英]C# How to create a solution with more than one same named projects?

I have been given a folder than contains many solutions in subfolders along with their code. 给了我一个文件夹,该文件夹包含子文件夹中的许多解决方案以及它们的代码。 Each solution builds a PrinterDriver.dll. 每个解决方案都会生成一个PrinterDriver.dll。 What I am trying to do is create a master solution that I can add all the projects into and then they will all compile every time. 我想要做的是创建一个主解决方案,可以将所有项目添加到其中,然后每次都将它们编译。

I cannot at the moment do this, when I add each to the master I get an alert telling me that a project of that name already exists. 目前,我无法执行此操作,将每个添加到主数据库时,都会收到警报,告诉我该名称的项目已经存在。 what is the best way to do this? 做这个的最好方式是什么?

I'd urge you not to create a master solution containing projects with the same name, that will end up a mess... You'll have to change assembly names and namespaces and as you've found you end up with dozens of namespace ambiguity errors. 我敦促您不要创建一个包含具有相同名称的项目的主解决方案,这将导致一团糟...您将不得不更改程序集名称和名称空间,并且发现您最终会获得数十个名称空间歧义错误。

all the projects ... will all compile every time 所有项目...都将每次都编译

If the aim is just to compile all the projects at once, every time, then simply write a MSBUILD script that uses all the project files to compile outputs. 如果目标只是每次一次编译所有项目,则只需编写一个MSBUILD脚本即可使用所有项目文件来编译输出。

Eg: Compiling a .vbproj or .csproj project file without Visual Studio 例如: 不使用Visual Studio编译.vbproj或.csproj项目文件


If you do want a master solution it will require surgery. 如果您确实需要高级解决方案,则需要进行手术。 One way would be to create interfaces (or abstract classes) that reflect the method signatures of each class in every project and using IoC load different implementation classes depending on the target. 一种方法是创建反映每个项目中每个类的方法签名的接口(或抽象类),并使用IoC根据目标加载不同的实现类。


Warning: Be wary about changing namespaces, while prefixing namespaces with a unique name may sound simple. 警告:警惕更改名称空间,而为名称空间添加唯一名称可能听起来很简单。 You have to be aware of the impact especially on code library's (like Printer.DLL) that other projects reference. 您必须意识到影响,特别是对其他项目引用的代码库(例如Printer.DLL)的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM