visual-studio C# dll 不跨项目更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1514574/
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
C# dll not updating across projects
提问by manobes
I've got a C# project in visual studio that is building a DLL, and another console project which includes the first as a reference. These are both in the same solution.
我在 Visual Studio 中有一个正在构建 DLL 的 C# 项目,以及另一个包含第一个作为参考的控制台项目。它们都在同一个解决方案中。
The trouble is when I add methods to the DLL, then rebuild the console project doesn't seem to pick them up.
问题是当我向 DLL 添加方法时,然后重建控制台项目似乎没有选择它们。
For example, in the DLL I have a class Converters. If I add a method
例如,在 DLL 中我有一个类转换器。如果我添加一个方法
public static void test() {}
it just doesnt' show up in the console app at all. Intellisense doesn't autocomplete it, and if I manually type it in it gives a compiler error.
它根本没有出现在控制台应用程序中。Intellisense 不会自动完成它,如果我手动输入它,则会出现编译器错误。
If I go in and delete the dll files then rebuild that works (or better yet, delete the bin and obj directories) but that seems rather drastic.
如果我进入并删除 dll 文件,然后重建该文件(或者更好的是,删除 bin 和 obj 目录),但这似乎相当激烈。
I'm sure this is a basic error, but I can't seem to find the solution after some googling.
我确定这是一个基本错误,但在谷歌搜索后我似乎无法找到解决方案。
回答by Steven Robbins
How are you adding the reference? As a project reference or by browsing to the DLL? If you're using the latter then it will copy it locally to the bin directory of your console app and won't refresh it unless you manually delete it. If you add it as a project reference it will copy it as and when it needs to.
你是如何添加引用的?作为项目参考还是通过浏览到 DLL?如果您使用后者,那么它会在本地将其复制到控制台应用程序的 bin 目录中,除非您手动删除它,否则不会刷新它。如果您将其添加为项目引用,它将在需要时复制它。
回答by Kobi
The exact thing happened to me once on a project - it turned out the build command wasn't configured to build these DLLs.
Check Build - Configuration Manager, and make sure the project is checked:
有一次在我的项目中发生了确切的事情 - 结果发现构建命令没有配置为构建这些 DLL。
检查Build - Configuration Manager,并确保项目被检查:
回答by WantToDo
close Project visualStudioand rebuild again your dll (other project visualStudio)
关闭 Project visualStudio并再次重建您的 dll(其他项目 visualStudio)
回答by Himansz
One of the things to note is the Target Framework of the Projects, if you compile your Project A with target framework different then that of Project B and it is referencing the dlls of Project A you may run into this kind of trouble. So, make sure that the target framework for both Projects is same.
需要注意的一件事是项目的目标框架,如果您编译项目 A 的目标框架与项目 B 的目标框架不同,并且它引用了项目 A 的 dll,您可能会遇到这种麻烦。因此,请确保两个项目的目标框架相同。
回答by Dan
Check that you don't have the ddl inside the bin folder of your project. Whilst I was adding the reference by browsing for the dll, I had forgotten that I manually copy pasted a version into that folder. No matter how many times I cleaned and rebuilt, it didn't seem to update.
检查项目的 bin 文件夹中是否没有 ddl。当我通过浏览 dll 添加引用时,我忘记了我手动将一个版本复制粘贴到该文件夹中。无论我清理和重建多少次,它似乎都没有更新。
Deleting that dll and re-referencing fixed the issue.
删除该 dll 并重新引用解决了该问题。
回答by marmont
check the folder which contains the reference. does it contain a refresh file with a relative path in it? if so, and if assembly names in the location pointed to by the relative path are common with those in of (project) references which should auto update, then these references no longer auto update! what you end up is a static reference to the assemblies present in the relative path contained in the refresh file. you may also have to delete the projectreferences key in the sln file and add references afresh
检查包含参考的文件夹。它是否包含带有相对路径的刷新文件?如果是这样,并且如果相对路径指向的位置中的程序集名称与应自动更新的(项目)引用中的程序集名称相同,则这些引用不再自动更新!您最终得到的是对刷新文件中包含的相对路径中存在的程序集的静态引用。您可能还需要删除 sln 文件中的 projectreferences 键并重新添加引用
回答by Tom Anderson
Change the reference to the dll to the Project, instead of the output.
将对 dll 的引用更改为项目,而不是输出。
回答by JaredPar
This is certainly unexpected behavior. It sounds like the reference between the two projects is broken in some way. Two issues come to mind.
这当然是意料之外的行为。听起来这两个项目之间的参考在某种程度上被打破了。想到两个问题。
- Possible problem with the reference. Try deleting the reference in solution explorer and readding the reference and seeing if that fixes things. When you re-add make sure it's a project reference and not a file reference.
- It's possible that the time stamps on the files in your project are off. See if they are in the future.
- 参考资料可能有问题。尝试删除解决方案资源管理器中的参考并阅读参考并查看是否可以解决问题。重新添加时,请确保它是项目引用而不是文件引用。
- 项目中文件的时间戳可能已关闭。看看他们是否在未来。
回答by Rafiki
I hate to beat a dead SO question but 8 years after the original question and none of the above solving the issue for me, my problem was in VS2013, but to solve it I simply removed and re-added the reference to the DLL in the project that invokes it.
我讨厌回答一个死的 SO 问题,但在原始问题出现 8 年后,上述问题都没有解决我的问题,我的问题是在 VS2013 中,但为了解决它,我只是删除并重新添加了对 DLL 的引用调用它的项目。
I hope this helps some people in the newer VS realm having the same issue.
我希望这可以帮助较新的 VS 领域中遇到相同问题的一些人。


