我在一个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文件的绝对路径…我读到过关于长度的问题。这是一个可能的问题吗?

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


当前回答

在我的案例中,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使用表达式体使编译器产生元数据错误而不是语法错误。

其他回答

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" />.

对我来说,问题是我打开了两个Visual Studio窗口,我的项目在一个窗口中运行调试,而我试图在另一个窗口中构建它。

我不得不停止调试,然后它让我成功构建。

VS2022:在这里的大量列表中没有发现原因。

拥有一个完全由静态方法组成的静态类。从类声明中删除static不会引发编译错误或警告,但会导致OP构建错误。

将类声明恢复为静态并修复了该问题。

在我的案例中,依赖项目(取决于错误消息中的项目)在项目的“属性→应用程序→程序集信息……”下的“程序集版本”字段中缺少值。我只是在“文件版本”中添加了相同的数字,点击“确定”,编译器错误就消失了!

事实证明,重新添加AssemblyVersion然后再次构建项目会导致另一个错误,该错误声称它已经出现在项目中。这是!在解决方案资源管理器中项目的属性节点下,有一个“SolutionVersionInfo.cs”文件,该文件还包含一个装配版本属性-从项目中删除该文件解决了此错误。

我在VS2019中也遇到了同样的问题。以下是你需要做的:

在某个分支上推送最新的更改 删除项目 从快速入门中删除项目-你可以尝试引用不存在的项目,它会要求你删除 克隆项目 运行项目