Assemblies not copied nor cleaned, and Visual Studio CS0006 Error when building

We were installing EPiServer Forms in a client’s EPiServer 9 website the other day, and encountered an issue with the binarier not being copied from the NuGet packages directory to the website’s bin folder.

EPiServer Forms assemblies missing from the bin directory of the website after Rebuild.

If we manually copied them there manually and then ran a Clean in Visual Studio, the EPiServer Forms assemblies would not be removed either.

EPiServer Forms assemblies not removed from bin directory on Clean in Visual Studio.

public ActionResult Index(ArticlePage currentPage)
{
  var foo = EPiServer.Forms.Constants.DefaultCulture;

Also, if we tried adding references to random stuff within the EPiServer Forms assemblies, or just adding a using for that matter.

using EPiServer.Forms;

We would get an error with code CS0006 saying that Metadata file ‘{path to assembly}.dll’ could not be found. for two of our projects.

Error code CS0006 when building Visual Studio project.

Fixing problem where assemblies not copied nor cleaned, and Visual Studio CS0006 Error

It turned out that the project in our solution were targeting the .Net Framework 4.5, whereas the EPiServer.Forms assemblies targeted 4.5.2. So upgrading the target framework in our projects to match the EPiServer assemblies fixed the problem.

A small checklist of things to try when faced with problems like this:

1. Remove the relevant references, and readd them manually.

2. Select relevant references, flip the Copy Local to False, save the solution, flip it to True and then save again. This will generate an XML node <Private>True</Private> in the csproj file for the references.

Select the references and toggle the Copy Local property to false, and then back to true in Visual Studio.

3. Unload the project and edit the csproj file. Ensure that you do indeed have the <Private>True</Private> tag on the relevant references.

Csproj file with private tag value true on references with the Copy Local property set in Visual Studio.

4. Make sure that you have the same target framework in all of your projects, and that it matches the target framework of the assemblies you are having problems with. Right click and select Properties on a project in Visual Studio to change framework.

Updating the target framework on Visual Studio projects.

5. Visual Studio does not copy assemblies that are dependencies to dependencies, unless they are also referenced in the main project. For instance, if project A depends on project B and project B depends on project C, then assembly C won’t be copied when building project A unless C is referenced in A. For more information, see Visual Studio does not copy referenced assemblies through the reference hierarchy.

Leave a Reply