我有两个有一些公共代码的解决方案,所以我想把它提取出来并在它们之间共享。此外,我希望能够独立地发布这个库,因为它可能对其他人有用。

用Visual Studio 2008最好的方法是什么? 一个项目是否存在于多个解决方案中? 对于这段单独的代码,我有单独的解决方案吗? 一个解决方案能依赖于另一个解决方案吗?


当前回答

一个项目可以被多个解决方案引用。

将库或核心代码放入一个项目中,然后在两个解决方案中引用该项目。

其他回答

在另一个项目中包含一个项目的类文件的一个更简单的方法是在现有解决方案中添加该项目,然后在现有项目中添加新项目的DLL引用。最后,您可以通过在任意类的顶部声明using指令来使用添加的类的方法。

您可以使用以下技术(这是@Andomar的解决方案保存在.csproj中的方法)内联通配符

<Compile Include="..\MySisterProject\**\*.cs">
  <Link>_Inlined\MySisterProject\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>

投入:

    <Visible>false</Visible>

如果你想隐藏文件和/或防止通配符包括被扩展,如果你添加或删除一个项目从“虚拟现有项目”文件夹,如上面的MySisterProject。

一个项目可以被多个解决方案引用。

将库或核心代码放入一个项目中,然后在两个解决方案中引用该项目。

现在您可以使用共享项目了

Shared Project is a great way of sharing common code across multiple application We already have experienced with the Shared Project type in Visual Studio 2013 as part of Windows 8.1 Universal App Development, But with Visual Studio 2015, it is a Standalone New Project Template; and we can use it with other types of app like Console, Desktop, Phone, Store App etc.. This types of project is extremely helpful when we want to share a common code, logic as well as components across multiple applications with in single platform. This also allows accessing the platform-specific API ’s, assets etc.

更多信息请看这个

File > Add > Existing Project…将允许您向当前解决方案添加项目。只是加上这个,因为上面的帖子都没有指出这一点。这允许您在多个解决方案中包含相同的项目。