Search code examples
c#msbuildcode-contracts

When building solution, ccrewrite fails with rewrite aborted due to metadata errors -> could not resolve type reference, fails on my machine only


I am having a really strange issue, when I try to build solution it fails

The command ""(solution)\packages\DotNet.Contracts.1.10.20606.1\Bin\ccrewrite.exe" "@(project)ccrewrite.rsp"" exited with code -1.

When I set detailed build output, I get some more information:

21>  Reading assembly 'xyz' from '(yyy)\bin\xyz.dll' resulted in errors.    
21>  ccrewrite : error : Rewrite aborted due to metadata errors. Check output window    
21>  Could not resolve type reference: [System.Web.Mvc]System.Web.Mvc.IClientValidatable.

What I tried so far:

  1. clean, rebuild, deleting bin folder
  2. upgrading Visual Studio to latest version
  3. repairing Visual Studio version

Btw, if I am Building that xyz project - it builds without problems From manage nuget packages for solution I see that Microsoft.Aspnet.Mvc is only in that "xyz" project

Seems like the same issue as here, but in my case it is VS 2017 and that question still has no answer...


Solution

  • Turned out, that project I was building which was failing when tried to ccrewrite for referenced library, had to have reference to Microsoft.Aspnet.Mvc package (although this project did not use it by it self, but by some reason it needed it for ccrewrite because this package was used in that referenced library). When I added this package problem was resolved

    So, if you experience this issue

    1) Set detailed build output (Tools->Options, Projects and Solutions->Build and Run, MSBuild project output verbosity->Detailed)

    2) check what is the error in Output window

    3) if it is about problems resolving type reference - check installed packages for the project which is failing (Reading assembly x from y most likely means, that y is missing some package which is installed for x)