我在一个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" />.

这里解释的大多数方法都不能为我解决这个问题。

最后,我通过以下步骤解决了这个问题:

1. 关闭Visual Studio。

2. 删除每个项目的bin文件夹中的所有内容。

3.开放解决方案并重新构建。

我遇到了同样的问题,但有另一种解决方案。

问题: 一个解决方案,多个项目。使用其他一些结果的主要应用程序失败了,它说:

CS0006:元数据文件“C:\Repos\TheApplication\TheApplicationCommon\bin\Debug\TheApplication.dll”找不到

但是实际上这个项目生成了C:\Repos\TheApplication\TheApplicationCommon\bin\Debug\TheApplicationCommon.dll 另一个项目也使用相同的dll编译完美。

在我更新使用PostSharp 3.x.x的内部nuget包之前。现在使用PostSharp 4.x.x.x。我的解决方法是把这个加到*里。csproj文件:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="...">
  <Import Project="..." Condition="..." />
  <PropertyGroup>
    ...
    <AssemblyName>TheApplication</AssemblyName>
    ...
    <SkipPostSharp>True</SkipPostSharp> <!-- This line -->
  </PropertyGroup>
...

另一个解决方案->清洁,另一个解决方案->重建,它在本地和构建服务器上工作。

希望它能帮助到别人。线程是旧的,相当长,但这个问题经常返回,我还没有看到这个解决方案。顺便说一下,使用Visual Studio 2017 (15.8.x)。

我遇到了这个问题。在我的情况下,我删除所有项目中的所有bin和obj文件夹,然后这个错误将为我解决。再试一次,解决这个问题

对我来说,问题发生了,因为我是内联变量。

因此,以下是成功的构建:

ReportCategory reportCategoryEnum;
Enum.TryParse(reportCategory, true, out reportCategoryEnum);

而当我修改我的代码如下,没有错误显示,但构建失败

Enum.TryParse(reportCategory, true, out ReportCategory reportCategoryEnum);