visual-studio “您是否缺少程序集参考?” 编译错误 - Visual Studio
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/450999/
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
"Are you missing an assembly reference?" compile error - Visual Studio
提问by Michael Kniskern
I am currently working on a server control for other applications in our company to interface with a WCF service. Every time I make a change code change and recompile the control, I increment the the AssemblyVerison and AssemblyFileVersion class in the AsseemblyInfo.cs by one. For example, my latest build went from 1.0.07.0 to 1.0.08.0.
我目前正在为我们公司的其他应用程序开发一个服务器控件,以便与 WCF 服务进行交互。每次更改代码并重新编译控件时,我都会将 AsseemblyInfo.cs 中的 AssemblyVerison 和 AssemblyFileVersion 类增加 1。例如,我的最新版本从 1.0.07.0 升级到 1.0.08.0。
When the consuming application updates the file by copying the latest file in the bin directory and tries to compile, they receive the following error:
当消费应用程序通过复制 bin 目录中的最新文件来更新文件并尝试编译时,它们会收到以下错误:
The type or namespace name 'MyControl' does not exist in the namespace 'MyNamespace' (are you missing an assembly reference?)
命名空间“MyNamespace”中不存在类型或命名空间名称“MyControl”(您是否缺少程序集引用?)
In order to resolve this error, they have to delete the current reference and re-add the reference.
为了解决这个错误,他们必须删除当前引用并重新添加引用。
Is there any way to update the server control without having to delete and re-add the reference?
有没有什么方法可以更新服务器控件而不必删除和重新添加引用?
I am not strong naming the server control.
@JPunyon - Do you mean have the consuming application add the server control project to their solution?
我不强命名服务器控件。
@JPunyon - 您的意思是让消费应用程序将服务器控制项目添加到他们的解决方案中吗?
采纳答案by Wim Coenen
Right-click the assembly reference in the solution explorer, properties, disable the "Specific Version" option.
在解决方案资源管理器中右键单击程序集引用,属性,禁用“特定版本”选项。
回答by EZDsIt
In my case it was a project defined using Target Framework: ".NET Framework 4.0 Client Profile " that tried to reference dll projects defined using Target Framework: ".NET Framework 4.0".
在我的例子中,它是一个使用 Target Framework 定义的项目:“.NET Framework 4.0 Client Profile”,它试图引用使用 Target Framework 定义的 dll 项目:“.NET Framework 4.0”。
Once I changed the project settings to use Target Framework: ".NET Framework 4.0" everything was built nicely.
一旦我更改了项目设置以使用 Target Framework:“.NET Framework 4.0”,一切都很好地构建。
Right Click the project->Properties->Application->Target Framework
右键项目->属性->应用程序->目标框架
回答by Dirk Vollmar
Are you strong-naming your assemblies? In that case it is not a good idea to auto-increment your build number because with every new build number you will also have to update all your references.
您是否对程序集进行强命名?在这种情况下,自动增加内部版本号并不是一个好主意,因为对于每个新的内部版本号,您还必须更新所有引用。
回答by Jin
I bumped the answer that pointed me in the right direction, but...
我碰到了为我指明正确方向的答案,但是......
For those who are using Visual C++:
对于那些使用 Visual C++ 的人:
If you need to turn off auto-increment of the version, you can change this value in the "AssemblyInfo.cpp" file (all CLR projects have one). Give it a real version number without the asterisk and it will work the way you want it to.
如果您需要关闭版本的自动递增,您可以在“AssemblyInfo.cpp”文件中更改此值(所有 CLR 项目都有一个)。给它一个不带星号的真实版本号,它就会按照你想要的方式工作。
Just don't forget to implement your own version-control on your assembly!
只是不要忘记在您的程序集上实现您自己的版本控制!
回答by Caleb Robinson
If none of the solutions above worked, try this 10-second fix.
如果上述解决方案均无效,请尝试此 10 秒修复程序。
Navigate to the startup project in solution explorer. Right click, properties> Application> Target framework. Change the target framework to anything else. Press Yesfor the confirmation dialog. Give the changes a few seconds to take effect, then switch the framework back to what it was before.
导航到解决方案资源管理器中的启动项目。右键单击,属性>应用程序>目标框架。将目标框架更改为其他任何内容。在确认对话框中按Yes。给更改几秒钟以使其生效,然后将框架切换回之前的状态。
The error will hopefully go away for you like it did for me!
该错误有望像对我一样对您消失!
回答by ket
In my case, I had to change the Copy Local setting to true (right-click assembly in solution explorer, select properties, locate and change value of Copy Local property). Once this setting was changed, publication of my WCF service copied the file to the server and the error went away.
就我而言,我必须将 Copy Local 设置更改为 true(在解决方案资源管理器中右键单击程序集,选择属性,找到并更改 Copy Local 属性的值)。更改此设置后,我的 WCF 服务的发布将文件复制到服务器,错误就消失了。
回答by user2063329
回答by Dennis T --Reinstate Monica--
I encountered this error with an Azure DevOps Services (MS-hosted) build pipeline on a TFVC repo.
我在 TFVC 存储库上的 Azure DevOps 服务(MS 托管)构建管道中遇到了此错误。
In my case, I was working within a branch and had accidentally added the reference from the package folder in trunk instead of from the branch. Once I added the reference from within the branch, it started compiling successfully.
就我而言,我在一个分支内工作,并且不小心添加了来自主干中的包文件夹而不是来自分支的引用。一旦我从分支中添加了引用,它就开始成功编译。
I.e., while working on \branch-beta\sierra.csproj, I accidentally referenced \trunk\packages\delta.dll. Obviously, I needed to reference \branch-beta\packages\delta.dll instead. The mixup occurred because the path is not prominently displayed in the Add Referencewindow and I didn't check carefully enough.
即,在处理\branch-beta\sierra.csproj 时,我不小心引用了\trunk\packages\delta.dll。显然,我需要改为引用 \branch-beta\packages\delta.dll。发生混淆是因为路径没有在“添加引用”窗口中突出显示,而且我没有仔细检查。
回答by Boris
I found this issue in Visual Studio 2019 Version 16.4.4
我在Visual Studio 2019 版本 16.4.4 中发现了这个问题
I resolved most issues by discovering that the
我发现大多数问题都解决了
packages.config
was missing the appropriate reference
缺少适当的参考
eg:
例如:
<package id="System.Runtime" version="4.3.0" targetFramework="net461" />


