C# 无法解析此引用。找不到程序集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14261412/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:13:02  来源:igfitidea点击:

Could not resolve this reference. Could not locate the assembly

c#.net

提问by arame3333

Everytime I build my solution, I get this error message:

每次构建解决方案时,都会收到以下错误消息:

Warning

3

Could not resolve this reference. Could not locate the assembly "StandardClassLibrary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

StandardClassLibrary

警告

3

无法解析此引用。无法找到程序集“StandardClassLibrary,Version=1.0.0.0,Culture=neutral,processorArchitecture=MSIL”。检查以确保程序集存在于磁盘上。如果您的代码需要此引用,您可能会收到编译错误。

标准类库

So my application has a number of projects of which StandardClassLibraryis one. The above message is a warning and as far as I can tell it does NOT have an impact on my solution.

所以我的应用程序有许多项目,其中StandardClassLibrary之一。以上消息是一个警告,据我所知,它不会对我的解决方案产生影响。

But I would rather it not be there, just in case...

但我宁愿它不在那里,以防万一......

采纳答案by C.Evenhuis

You most likely get this message when the project points to an old location of the assembly where it no longer exists. Since you were able to build it once, the assembly has already been copied into your bin\Debug/ bin\Releasefolders so your project can still find a copy.

当项目指向它不再存在的装配的旧位置时,您很可能会收到此消息。由于您能够构建一次,因此程序集已经复制到您的bin\Debug/bin\Release文件夹中,因此您的项目仍然可以找到副本。

If you open the references node of the project in your solution explorer, there should be a yellow icon next to the reference. Remove the reference and add it again from the correct location.

如果在解决方案资源管理器中打开项目的引用节点,引用旁边应该有一个黄色图标。删除引用并从正确的位置再次添加它。

If you want to know the location it was referenced from, you'd have to open the .csproj file in a text editor and look for the HintPathfor that assembly - the IDE for some reason does not show this information.

如果您想知道它被引用的位置,您必须在文本编辑器中打开 .csproj 文件并查找HintPath该程序集 - IDE 出于某种原因不显示此信息。

回答by user1682406

Check if your project files are read-only. Remove the read-only property by right clicking on the project folder and select properties. In the properties screen remove the read-only checkbox. I came across the same problem, and this solved it for me.

检查您的项目文件是否为只读。通过右键单击项目文件夹并选择属性来删除只读属性。在属性屏幕中删除只读复选框。我遇到了同样的问题,这为我解决了。

回答by Alex Strickland

This confused me for a while until I worked out that the dependencies of the various projects in the solution had been messed up. Get that straight and naturally your assembly appears in the right place.

这让我困惑了一段时间,直到我发现解决方案中各个项目的依赖关系已经搞砸了。直截了当,您的程序集自然会出现在正确的位置。

回答by scsfdev

If the project is check out to different PC through team foundation server with different location of same library file, there will be no yellow icon mark in Reference but when change to Release build and build the project, it will give an error. Just like what @C.Evenhuissaid, it will use back old one in previous build (eg: Debug build) so I didn't notice the mistake.

如果项目通过team Foundation server 检出到不同PC,相同库文件的不同位置,Reference 中不会有黄色图标标记,但是当更改为Release build 并构建项目时,会报错。就像@C.Evenhuis所说的那样,它会在以前的构建中使用旧的(例如:调试构建),所以我没有注意到这个错误。

Now I know it is a bad habit to put library files in different location on different PC.

现在我知道将库文件放在不同 PC 上的不同位置是一个坏习惯。

Just need to delete the reference and re-add the same reference from correct location.

只需要删除引用并从正确的位置重新添加相同的引用。

回答by BHoltzman

I had the same warning in VS 2017. As it turned out in my case I had added a unit test project and needed to set a dependency for the unit test on the DLL it was testing.

我在 VS 2017 中也有同样的警告。事实证明,在我的情况下,我添加了一个单元测试项目,并且需要为正在测试的 DLL 上的单元测试设置依赖项。

回答by Martin Brandl

If anyone face this issue with some nugetpackages, you can fix that by reinstalling the packages using the Package Manager Console:

如果有人在使用某些nuget包时遇到此问题,您可以通过使用包管理器控制台重新安装包来解决该问题:

Update-Package -reinstall 

回答by Janis

Maybe it will help someone, but sometimes Name tag might be missing for a reference and it leads that assembly cannot be found when building with MSBuild. Make sure that Nametag is available for particular reference csproj file, for example,

也许它会帮助某人,但有时名称标签可能会丢失以供参考,这会导致在使用 MSBuild 构建时无法找到程序集。确保该Name标签可用于特定的参考 csproj 文件,例如,

    <ProjectReference Include="..\MyDependency1.csproj">
      <Project>{9A2D95B3-63B0-4D53-91F1-5EFB99B22FE8}</Project>
      <Name>MyDependency1</Name>
    </ProjectReference>

回答by Jose A

If you have built an image with Docker, and you're getting these strange messages:

如果您已经使用 Docker 构建了一个映像,并且您会收到这些奇怪的消息:

warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Extensions.Configuration.Abstractions". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/src/Utilities/Utilities.csproj]

警告 MSB3245:无法解析此引用。找不到程序集“Microsoft.Extensions.Configuration.Abstractions”。检查以确保程序集存在于磁盘上。如果您的代码需要此引用,您可能会收到编译错误。[/src/Utilities/Utilities.csproj]

Open the affected projectUtilities/Utilities.csproj, (You shall look for your project). You may need to choose Unload Project from the menu first. Right click on the .csproj file and edit it.

打开受影响的项目Utilities/Utilities.csproj,(你应该寻找你的项目)。您可能需要先从菜单中选择卸载项目。右键单击 .csproj 文件并进行编辑。

Now, delete all the <HintPath>tags

现在,删除所有<HintPath>标签

Save, and try again.

保存,然后重试。

enter image description here

enter image description here

enter image description here

enter image description here

回答by glihm

in 2020, this behavior still present with VS2019. (even if I clean projects from the solution explorer in VS2019, this not solves the problem)

在 2020 年,这种行为仍然存在于 VS2019 中。(即使我在 VS2019 中从解决方案资源管理器中清除项目,这也不能解决问题)

The solution that worked for mewas to open the folder of the project, and manually remove the \bin and \obj directories.

对我有用的解决方案是打开项目的文件夹,然后手动删除 \bin 和 \obj 目录。