четверг, 15 августа 2013 г.

How to fix Ncrunch in Visual Studio 2013 Preview for code analyse

If you have a following error in NChrunch 2013:

..\..\..\..\..\..\..\..\..\..\..\..\..\..\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.targets (298)#0: The "CodeAnalysis" task could not be instantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\.\FxCopTask.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.CodeAnalysis' to type 'Microsoft.Build.Framework.ITask'.
..\..\..\..\..\..\..\..\..\..\..\..\..\..\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.targets (298)#1: The "CodeAnalysis" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
You can easily fix it!

Backup "Microsoft.CodeAnalysis.Targets" in c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis : i named it  "Microsoft.CodeAnalysis.Targets_2013" 

Copy file from 2012 to 2013 folder
c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.Targets
=> to
c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.Targets


Open for editing: (best to open in VS)
  c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.Targets


Replace all occurences of  
AssemblyFile=".\FxCopTask.dll" 
to  the old vesion of VS =>
AssemblyFile="c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\FxCopTask.dll"

So it will look like 
    <UsingTask TaskName="Microsoft.Build.Tasks.NativeCodeAnalysis" AssemblyFile="c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\CodeAnalysis\FxCopTask.dll"/>


That's all. 

Resynchronize NChrunch.

2 комментария:

  1. I'm glad theres a work around. But what if I want to use VS 2013 without NCrunch...is there anyway to allow the native code analysis task to work?

    ОтветитьУдалить
  2. I Did research for that and there are really poor tools and support for native code. Even more - there are a lot of frameworks (Qt, Boost, etc) and each offers very different capabilities.
    I would wait for JetBrains C++ IDE.

    Now there are libraries like CppUnit

    ОтветитьУдалить