M.Y. Babt
M.Y. Babt

Reputation: 2891

Metadata files for references not found

I use MSBuild Version 14.0.

Following the documentation here, I defined my own Build task like this:

<Target Name="Build" 
        Inputs="@(Compile)"
        Outputs="MyLibrary.dll">

        <Csc 
            Sources="@(Compile)"
            Resources="@(EmbeddedResource)" 
            References="@(Reference);@(ProjectReference)" 
            OutputAssembly="MyLibrary.dll"/>
</Target> 

In one of my ItemGroups, I added the following references:

<Reference Include="System" />
<Reference Include="System.Core">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />

However, the build failed because of these errors:

CSC : error CS0006: Metadata file 'System' could not be found [C:\MyLibrary.csproj]
CSC : error CS0006: Metadata file 'System.Core' could not be found C:\MyLibrary.csproj]
CSC : error CS0006: Metadata file 'System.Runtime.Serialization' could not be found [C:\MyLibrary.csproj]
CSC : error CS0006: Metadata file 'System.Xml' could not be found [C:\MyLibrary.csproj]

How can I fix this?

EDIT: I think MSBuild threw that error because all of the DLLs mentioned in the error messages above are located in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\, instead of inside the folder containing my .csproj file. I would prefer not to copy and paste those references into my project folder. What should I do to ensure that those DLLs can be correctly located?

Upvotes: 0

Views: 676

Answers (1)

Leo Liu
Leo Liu

Reputation: 76740

What should I do to ensure that those DLLs can be correctly located?

After check the documentation How to: Build Incrementally more carefully, I found that we should include the file type suffix .dll in those references, otherwise, Csc.exe compiler could not find those files. So you ItemGroup should be:

  <ItemGroup>
    <Reference Include="System.dll" />
    <Reference Include="System.Core.dll">
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    </Reference>
    <Reference Include="System.Runtime.Serialization.dll" />
    <Reference Include="System.Xml.dll" />
  </ItemGroup>

enter image description here

Upvotes: 1

Related Questions