C# 由于缺少并非缺少的程序集引用,Visual Studio 拒绝构建项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29962432/
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
Visual Studio refuses to build project due to missing assembly reference that isn't missing
提问by user1531921
I'm building a c# windows service and has added a couple of assembly references (to other projects of my own) to my project.
我正在构建 ac# windows 服务,并在我的项目中添加了几个程序集引用(对我自己的其他项目)。
I get the following error when I build:
我在构建时收到以下错误:
"Error 25 The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?"
“错误 25 找不到类型或命名空间名称 'TestClass'(您是否缺少 using 指令或程序集引用?”
Interestingly enough, the reference path in the csproj-file is correct, and on top of that, classes and namespaces from the referenced project, that according to Visual Studio is missing, is being picked up by Intellisense and even the "go to definition" function works fine. Furthermore, I have other projects in the exact same folder as my new windows service and they picked up the assembly references just fine. All the referenced projects are included in the solution.
有趣的是,csproj 文件中的引用路径是正确的,除此之外,根据 Visual Studio 缺少的引用项目中的类和命名空间被 Intellisense 拾取,甚至“转到定义”功能工作正常。此外,我在与我的新 Windows 服务完全相同的文件夹中有其他项目,他们很好地获取了程序集引用。所有引用的项目都包含在解决方案中。
I use Visual Studio 2013 Update 3. There is really no code that I could show that would give you more information, but let me know if you want to see some screenshots or something.
我使用 Visual Studio 2013 更新 3。我真的没有代码可以显示可以为您提供更多信息,但是如果您想查看一些屏幕截图或其他内容,请告诉我。
Attempts so far:
迄今为止的尝试:
- Tried restarting VS and reloading all projects
- Tried adding the paths to the properties reference paths page.
- Tried all steps in this guide: https://msdn.microsoft.com/en-us/library/ayds71se.aspx
- 尝试重新启动 VS 并重新加载所有项目
- 尝试将路径添加到属性引用路径页面。
- 尝试了本指南中的所有步骤:https: //msdn.microsoft.com/en-us/library/ayds71se.aspx
UpdateWhen I select one of the "missing" references in the reference list, and go to properties, there is no path defined. Yet, the relative path is in the csproj-file as is correct. Confusing.
更新当我在引用列表中选择“缺失”引用之一并转到属性时,没有定义路径。然而,相对路径在 csproj 文件中是正确的。令人困惑。
Update 2Removing all the references, reloading the projects and then doing a clean fixed it for me. Apparently, the problem was caused by all dlls not being updated in the build stack.
更新 2删除所有引用,重新加载项目,然后为我做一个干净的修复。显然,该问题是由于所有 dll 未在构建堆栈中更新造成的。
采纳答案by nayef harb
回答by zmaten
Another possible issue could be mismatch in targeted versions of .NETbetween the assemblies. I experienced the same symptoms and setting the same version of framework did the trick for me.
另一个可能的问题可能是程序集之间的.NET 目标版本不匹配。我遇到了相同的症状,并且设置相同版本的框架对我有用。
回答by mayank
In my case, target Framework of Assembly Project and the target Framework of the project where i want to use this assembly are different. Target framework of assembly project was 4.5 and target framework of my project was 4.0.
就我而言,程序集项目的目标框架和我要使用此程序集的项目的目标框架不同。汇编项目的目标框架是4.5,我项目的目标框架是4.0。
When I have change the target framework of my project to the target framework of assembly project i.e. from 4.0 to 4.5 , it works fine.
当我将项目的目标框架更改为组装项目的目标框架时,即从 4.0 到 4.5 ,它工作正常。
For change the Target Framework of project,
对于更改项目的目标框架,
Right Click the project -> Properties -> Application -> Target Framework
右键项目 -> 属性 -> 应用程序 -> 目标框架
This Target Framework is drop-down list, select your required Framework from this list.
此目标框架是下拉列表,请从此列表中选择所需的框架。
回答by Iizuki
I the same problem. Or at least the symptoms were same. My solution was located on a network drive. Moving the solution to my local drive solved the problem for me.
我同样的问题。或者至少症状是一样的。我的解决方案位于网络驱动器上。将解决方案移动到我的本地驱动器为我解决了这个问题。
The reason was apparently that Windows 10 didn't see the network drive as a trusted enough location. It worked fine until I managed to break my solution somehow. Visual studio apparently didn't have the required rights to perform needed the fixing operations.
原因显然是 Windows 10 没有将网络驱动器视为足够受信任的位置。它运行良好,直到我设法以某种方式打破我的解决方案。Visual Studio 显然没有执行所需的修复操作所需的权限。
回答by Ryan Varley
Reinstalling packages worked for me.
重新安装软件包对我有用。
From the Package Manager Console, run the the following command to reinstall all packages.
从包管理器控制台,运行以下命令以重新安装所有包。
update-package -reinstall
update-package -reinstall
You can target a single package with:
您可以使用以下方式定位单个包:
update-package PACKAGE_NAME -reinstall
update-package PACKAGE_NAME -reinstall

