我试图使用c# 4.0编译我的excel插件,并在Visual Studio中构建我的项目时开始遇到这个问题。重要的是要告诉你,我以前从来没有遇到过这个问题。什么会导致这种情况发生?
当前回答
我得到类似的编译器错误。一旦我将dll文件的依赖项目添加到解决方案中,问题就解决了。
其他回答
这里有一个不同的方法来解决这个问题:
右键单击项目并选择“卸载项目”选项。您将注意到您的项目变得不可用。 右键单击不可用项目并选择“Edit”选项。 向下滚动到包含所有资源标记的“< ItemGroup >”标记。 现在转到已经显示在错误列表中的引用,您将注意到它使用了单个标记(即< reference Include="assemble_name_here, Version=0.0.0.0, Culture=neutral" / >)。 更改为如下所示:
.
<Reference Include="assemble_name_here, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" >
< Private > True < / Private >
< HintPath > path_here\assemble_name_here.dll < / HintPath >
< / Reference >
保存您的更改,再次右键单击不可用的项目,然后单击“重新加载项目”选项,然后构建。
如果你试了这个问题的所有其他答案,你会:
您的解决方案中有多个项目 有一个项目(项目a)引用另一个项目(项目B),后者的项目引用一个NuGet包。 在项目A中,您使用Intellisense/ReSharper引入项目B中引用的NuGet包的引用(当项目B中的方法返回由NuGet包提供的类型并且该方法在项目A中使用时,这可能会发生) 通过NuGet包管理器(或CLI)更新NuGet包。
...你可能在你的项目的引用中有不同版本的NuGet包DLL,因为Intellisense/ReSharper创建的引用将是一个“正常的”引用,而不是预期的NuGet引用,所以NuGet更新过程不会发现或更新它!
要解决这个问题,请删除项目A中的引用,然后使用NuGet安装它,并确保所有项目中的NuGet包都是相同的版本。(如回答中所述)
生活小贴士:
当ReSharper/Intellisense建议添加一个引用到你的项目时,这个问题就会出现。它可能比上面的例子复杂得多,多个交织的项目和依赖关系使其难以跟踪。如果ReSharper/Intellisense建议的引用实际上来自NuGet包,使用NuGet来安装它。
为任何人添加我的解决方案,这可能会有所帮助。
I had a ClickOnce solution throwing this error. The app referenced a common "Libs" folder and contained a project reference to a Foo.dll. While none of the projects in the solution referenced the static copy of the Foo.dll in the "Libs" folder, some of the references in that folder did (ie: my solution had refs to Libs\Bar.dll which referenced Foo.dll.) Since the CO app pulled all the dependencies from Libs as well as their dependencies, both copies were going into the project. This was generating the error above.
我通过将我的Libs\Foo.dll静态版本移动到一个子文件夹Libs\Fix\Foo.dll来解决这个问题。此更改使ClickOnce应用程序只使用DLL的项目版本,并且错误消失了。
I recently hit this problem. In my case, I have NuGet packages on different assemblies. What I had was different versions of the same NuGet packages associated with my own assemblies. My solution was to use the NuGet package manager upon the Solution, as opposed to the individual projects. This enables a "consolidation" option, where you can upgrade your NuGet packages across as many projects as you want - so they all reference the same version of the assembly. When I did the consolidations, the build failure disappeared.
在尝试了这里的大多数解决方案后,我最终只是从点击一次项目中添加了一个引用,这将它从包括更改为包括(自动),它最终工作了。
推荐文章
- 实体框架核心:在上一个操作完成之前,在此上下文中开始的第二个操作
- 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
- 为什么Visual Studio 2015/2017/2019测试运行器没有发现我的xUnit v2测试
- 如何使用JSON确保字符串是有效的JSON。网
- AppSettings从.config文件中获取值
- 通过HttpClient向REST API发布一个空体
- 如何检查IEnumerable是否为空或空?
- 自动化invokerrequired代码模式
- 在c#代码中设置WPF文本框的背景颜色
- Visual Studio复制项目
- 在c#中,什么是单子?
- c#和Java中的泛型有什么不同?和模板在c++ ?
- c#线程安全快速(est)计数器
- 如何将此foreach代码转换为Parallel.ForEach?
- 如何在iis7应用程序池中设置。net Framework 4.5版本