如何保持在C#项目之间共享公共代码? [英] How do I keep common code shared between projects in c#?

查看:231
本文介绍了如何保持在C#项目之间共享公共代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点新的C#,我试图找出保持公共代码的地方,用几个项目一个很好的解决方案。

I'm kinda new to c# and I'm trying to figure out a good solution for keeping common code somewhere that is used by several projects.

首先,我试图保持它在cs文件,并将其添加到需要的代码的项目,但这份如果我做的通用代码也不会在使用此代码的各个项目中反映任何更改该文件的意义。

First I tried keeping it in a .cs file and add it to the projects that needs the code, but this COPIES the file meaning if I do any changes to the common code it will not be reflected in the various projects using this code.

然后我试图创建一个类库,而不是使用该代码的项目中引用的DLL。首先,我不能得到这个,虽然我下面的教程甚至工作,甚至当我引用我仍然不能以某种方式使用它的DLL,但即使这个工作,它仍然需要一个额外的DLL与我的应用程序进行捆绑一些常见的代码,这不是我想要的。

Then I tried creating a class library instead and reference the DLL within the projects using the code. First of all I can't get this to work even though I am following the tutorials, Even when I reference the DLL I still cannot use it somehow, but even if this worked it still needs an extra DLL to be bundled with my app for some common code and that is not what I want.

有没有什么办法让被无需发运DLL是W

Is there any way to keep common code that is REFERENCED without needing to ship a DLL w

推荐答案

最好的解决办法是让您在每个项目一个共同的参照库。但是你说你不想这样做,因为它需要捆绑其他DLL,真的是什么大不了的问题?你还别说,你不能得到那个工作,发布错误等的细节,我们将能够提供帮助。

The best solution is to have a common library that you reference in each of your projects. However you say you don't want to do that as it requires bundling additional dlls, is that really that big a issue? You also mention that you can't get that to work, post the details of errors etc and we will be able to help.

另一种选择,假设你使用的是Visual工作室是常见的文件链接到你的项目,而不是添加它。这将使通用文件在当前位置,而不是将其移动到你的项目目录。

Another option, assuming you are using Visual Studio is to link the common file into your project rather than add it. This will keep the common file in its current location and not move it into your project directory.

要做到这一点,去添加现有文件对话框,但是,从添加按钮,点击向下箭头并选择链接来代替。

To do this, go to the add existing file dialog but on the 'Add' button click the down arrow and select 'Link' instead.

如上使用公共库提的是最好的解决办法,所以如果捆绑销售,这是一个无法克服的问题,你可以看看到使用ilmerge。这将合并所有您的dll / EXE文件到一个文件,然后可以部署。

As mentioned above using a common library is the best solution so if bundling this is a unsurmountable issue you could look into using ilmerge. This will merge all your dlls/exes into a single file that you can then deploy.

这篇关于如何保持在C#项目之间共享公共代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆