我在一个WPF, c# 3.0项目上工作,我得到了这个错误:

Error 1 Metadata file
'WORK=- \Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug
\BusinessLogicLayer.dll' could not be found C:\-=WORK=- \Tools
\VersionManagementSystem\VersionManagementSystem\CSC VersionManagementSystem

这是我如何引用我的usercontrols:

xmlns:vms="clr-namespace:VersionManagementSystem"
<vms:SignOffProjectListing Margin="5"/>

每次构建失败后都会发生这种情况。我能得到解决方案编译的唯一方法是注释掉所有用户控件并重新构建项目,然后取消注释用户控件,一切正常。

我已经检查了构建顺序和依赖项配置。

正如你所看到的,它似乎截断了DLL文件的绝对路径…我读到过关于长度的问题。这是一个可能的问题吗?

注释、构建和取消注释是非常烦人的,构建变得非常烦人。


当前回答

The Visual Studio IDE doesn't do any building behind the scenes, the Msbuild application does. The VS IDE essentially just constructs the project file that is used by Msbuild and quite often it makes mistakes if you leave it up to the IDE to figure things out on it's own. If you are getting the Metadata file '.dll' could not be found error it is likely due to the fact that the correct/expected assemblies are not being found. So perhaps Visual Studio might be creating a project file for a 4.5 framework app, and expecting 4,5 assemblies, while you are referencing 4.0 assemblies. So look at your Visual Studio settings for incompatibilities or go into the project file yourself, and manually fix it by specifying the correct path <Reference Include="C:\\correct path to assembly\\yourAssembly.dll" />.

其他回答

我有这个问题,因为.nuget\NuGet.exe不包括在我的存储库。虽然我在NuGet中启用了DownloadNuGetExe。目标,它报告了一个代理错误时,试图下载它。这导致项目构建的其余部分失败。

我今天在VS2022的一个Blazor项目的解决方案中击中并解决了这个问题。

潜在的问题是我引入了一个常规的c#编译错误 在。razor文件中声明的c#代码。VS2022正在从“生成错误列表”选项卡中删除错误显示。我通过在output控制台日志选项卡中扫描构建输出发现了c#错误,我的c#错误被描述为预期的。

附注:如果你想知道,我有一个单元测试项目引用我的Blazor web项目。从单元测试项目到Blazor应用程序的项目DLL引用正在抱怨缺少Blazor DLL。

在我的案例中,ReSharper是愚蠢的,即使我的项目目标是c# 6,我也被提供了重构来使用c# 7独有的特性。

出于这个原因,我最终修改了这段代码,

private DateTime? _joinedDate;
[Column(TypeName = "DateTime2")]
public DateTime JoinedDate
{
    get { return _joinedDate ?? DateTime.Now; }
    set { _joinedDate = value; }
}

进入这段代码:

private DateTime? _joinedDate;
[Column(TypeName = "DateTime2")]
public DateTime JoinedDate
{
    get => _joinedDate ?? DateTime.Now;
    set => _joinedDate = value;
}

由于某种原因,让getter和setter使用表达式体使编译器产生元数据错误而不是语法错误。

在我的例子中,我以错误的方式获得了安装目录。

如果您的解决方案路径类似于“我的项目%2c非常流行%2c单元测试%2c软件和硬件。zip”,它不能解析元数据文件,也许我们应该防止一些无效的单词,如%2c。

当从某些站点克隆存储库时,目录名是URL编码的。它将把目录名中的空格字符转换为%20,正斜杠转换为%2f,下划线转换为%5f,等等。虽然,我不确定为什么%符号会破坏事情。

将路径重命名为正常名称解决了我的问题。

哇,看起来这个错误可能来自任何地方。

无论如何,我添加了一个新的WebAPI控制器到我的MVC应用程序,它自动魔术般地从NuGet得到所有的引用。后来我从NuGet UI中删除了引用,但我忘记删除使用它们的文件(即System.Http)。

出于某种原因,我收到的错误是这样的,以及一个关于未使用变量的简单警告。

我注释掉了变量,至少摆脱了警告,重新构建指出了所有使用不存在引用的文件。删除这些文件后,一切正常。