locked
FxCop can't find EnvDTE Version 7.0.3300.0

    Question

  • I'm trying to run Code Analysis on a Dsl project that references the VSProjLang assembly (

    Is there a way of telling FxCop to use EnvDTE Version 8.0.0.0 that ships with VS2008?

    This is the error I'm seeing:

    Code Block

    Running Code Analysis...
    C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe  /outputCulture:1033 /out:"bin\Debug\Altinoren.ActiveWriter.Dsl.dll.CodeAnalysisLog.xml" /file:"bin\Debug\Altinoren.ActiveWriter.Dsl.dll" /dictionary:"..\CodeAnalysisDictionary.xml" /directory:"C:\Program Files\Common Files\Microsoft Shared\MSEnv\PublicAssemblies" /directory:"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies" /directory:"C:\Windows\Microsoft.NET\Framework\v2.0.50727" /directory:"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies" /directory:"C:\Program Files\Microsoft Visual Studio 2008 SDK\VisualStudioIntegration\Common\Assemblies" /directory:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5" /rule:"C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules" /searchgac /ignoreinvalidtargets /forceoutput /successfile /ignoregeneratedcode /saveMessagesToReport:Active /timeout:120
    MSBUILD : error : CA0001 : The following error was encountered while reading module 'Altinoren.ActiveWriter.Dsl': Assembly reference not resolved: EnvDTE, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
    MSBUILD : error : CA0058 : The referenced assembly 'EnvDTE, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be found. This assembly is required for analysis and was referenced by: 'Altinoren.ActiveWriter.Dsl.dll'.
    Code Analysis Complete -- 2 error(s), 0 warning(s)


    It appears that FxCop doesn't understand bind redirects.

    -dave
    Tuesday, November 27, 2007 2:59 AM

Answers

  • We don't respect binding redirects because we are based on build-time (where we analyze using the same references you are built against) rather than than run-time.

     

    We are trying to find EnvDTE v7, because we are seeing a direct reference to it within the assembly itself. Do you have a reference to it within the project? If not, can you tell me the other references you have?

     

    There is an unsupported way of getting Code Analysis 2008/FxCop 1.36 to ignore versions when resolving, to turn it on, do the following:

     

    1. Open C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis\FxCop\FxCopCmd.exe.config in a text editor
    2. Change the value of  AssemblyReferenceResolveMode setting to StrongNameIgnoringVersion

    Regards

     

    David

     

     

     

    Wednesday, November 28, 2007 3:12 AM
    Moderator
  • David,

     

    Okay I've repro'd this - this is what is happening (I'm adidng this for others that might hit this):

     

    As you've pointed out VSLangProj exposes some types from EnvDTE v7. However, the C# compiler allows you to compile against VSLangProj, while substituting the v7 version of those types with the v8 version. While this won't actually run without a binding redirect - Visual Studio does actually give a warning in the Error List if you are building a Console or Windows Application that reminds you to one.

     

    Now the problem with this for Code Analysis is that like the CLR itself, we do not consider types from a later version of a assembly to be the same as types from the associated types in the earlier version. This could lead to two problems:

     

    1) In some situations we'll fail analysis because we can not locate the previous version of the assembly. This is what you are hitting.

     

    2) In other situations, we'll fail to actually resolve members and in the Error List we'll output something like:

     

    CA0055 : Could not load References.exe.
    CA0052 : No targets were selected.

     

    Opening the CodeAnalysisLog.xml in the output directory will have something like:

     

    <Exceptions>
      <Exception Keyword="CA0055" Kind="AssemblyLoad">
       <Type>Microsoft.FxCop.Common.AssemblyLoadException</Type>
       <ExceptionMessage>Could not load References.exe.</ExceptionMessage>
       <InnerType>Microsoft.FxCop.Sdk.InvalidMetadataException</InnerType>
       <InnerExceptionMessage>The following error was encountered while reading module 'References': Could not resolve member reference: VSLangProj.BuildManager::get_ContainingProject.</InnerExceptionMessage>
       <InnerStackTrace>   at Microsoft.FxCop.Sdk.Reader.HandleError(ModuleNode mod, String errorMessage)
       at Microsoft.FxCop.Sdk.Reader.GetMemberFromRef(Int32 i, TypeNodeCollection&amp; varArgTypes, Int32 numGenericArgs)
       at Microsoft.FxCop.Sdk.Reader.GetMethodDefOrRef(Int32 codedIndex)
       at Microsoft.FxCop.Sdk.Reader.GetTypeMembers(TypeNode type, Object handle)
       at Microsoft.FxCop.Sdk.TypeNode.get_Members()
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.VisitType(TypeNode type, TargetType target)
       at Microsoft.FxCop.Engines.Introspection.BaseVisitor.VisitTypes(TypeNodeCollection types, TargetNamespaceDictionary targets)
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.VisitModule(ModuleNode module, TargetModule target)
       at Microsoft.FxCop.Engines.Introspection.BaseVisitor.VisitAssembly(AssemblyNode assembly, TargetFile target)
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.VisitAssembly(AssemblyNode assembly, TargetFile target)
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.Load(TargetFile target, Boolean buildTree, Boolean queueItems, AssemblyNode loadedAssembly)
       at Microsoft.FxCop.Engines.Introspection.IntrospectionAnalysisEngine.LoadTargets(TargetFile target)
       at Microsoft.FxCop.Common.EngineManager.LoadTargets(TargetFile target, Boolean resetCounts, String loadEngine)</InnerStackTrace>
      </Exception>
      <Exception Keyword="CA0052" Kind="Engine">
       <Type>Microsoft.FxCop.Sdk.FxCopException</Type>
       <ExceptionMessage>No targets were selected.</ExceptionMessage>
      </Exception>
     </Exceptions>

     

    For the moment, there are two workarounds:

     

    1) Add a reference to older the version of the assembly. In some cases, such as above where EnvDTE v7 is not shipped, that is not possible.

     

    2) Change the Code Analysis assembly resolving logic as mentioned above.

     

    I've filed a bug on this and in a future service Pack or release, it is likely that we will fix this behavior.

     

    Thank you for bringing this to our attention.

     

    Regards


    David

    Wednesday, November 28, 2007 9:38 PM
    Moderator

All replies

  • We don't respect binding redirects because we are based on build-time (where we analyze using the same references you are built against) rather than than run-time.

     

    We are trying to find EnvDTE v7, because we are seeing a direct reference to it within the assembly itself. Do you have a reference to it within the project? If not, can you tell me the other references you have?

     

    There is an unsupported way of getting Code Analysis 2008/FxCop 1.36 to ignore versions when resolving, to turn it on, do the following:

     

    1. Open C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis\FxCop\FxCopCmd.exe.config in a text editor
    2. Change the value of  AssemblyReferenceResolveMode setting to StrongNameIgnoringVersion

    Regards

     

    David

     

     

     

    Wednesday, November 28, 2007 3:12 AM
    Moderator
  • My project references the VSLangProj assembly.

    This is shipped with VS 2008, but according to Reflector, VSLangProj contains a reference to the older EnvDTE assembly.

    -dave
    Wednesday, November 28, 2007 3:17 AM
  • David,

     

    Okay I've repro'd this - this is what is happening (I'm adidng this for others that might hit this):

     

    As you've pointed out VSLangProj exposes some types from EnvDTE v7. However, the C# compiler allows you to compile against VSLangProj, while substituting the v7 version of those types with the v8 version. While this won't actually run without a binding redirect - Visual Studio does actually give a warning in the Error List if you are building a Console or Windows Application that reminds you to one.

     

    Now the problem with this for Code Analysis is that like the CLR itself, we do not consider types from a later version of a assembly to be the same as types from the associated types in the earlier version. This could lead to two problems:

     

    1) In some situations we'll fail analysis because we can not locate the previous version of the assembly. This is what you are hitting.

     

    2) In other situations, we'll fail to actually resolve members and in the Error List we'll output something like:

     

    CA0055 : Could not load References.exe.
    CA0052 : No targets were selected.

     

    Opening the CodeAnalysisLog.xml in the output directory will have something like:

     

    <Exceptions>
      <Exception Keyword="CA0055" Kind="AssemblyLoad">
       <Type>Microsoft.FxCop.Common.AssemblyLoadException</Type>
       <ExceptionMessage>Could not load References.exe.</ExceptionMessage>
       <InnerType>Microsoft.FxCop.Sdk.InvalidMetadataException</InnerType>
       <InnerExceptionMessage>The following error was encountered while reading module 'References': Could not resolve member reference: VSLangProj.BuildManager::get_ContainingProject.</InnerExceptionMessage>
       <InnerStackTrace>   at Microsoft.FxCop.Sdk.Reader.HandleError(ModuleNode mod, String errorMessage)
       at Microsoft.FxCop.Sdk.Reader.GetMemberFromRef(Int32 i, TypeNodeCollection&amp; varArgTypes, Int32 numGenericArgs)
       at Microsoft.FxCop.Sdk.Reader.GetMethodDefOrRef(Int32 codedIndex)
       at Microsoft.FxCop.Sdk.Reader.GetTypeMembers(TypeNode type, Object handle)
       at Microsoft.FxCop.Sdk.TypeNode.get_Members()
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.VisitType(TypeNode type, TargetType target)
       at Microsoft.FxCop.Engines.Introspection.BaseVisitor.VisitTypes(TypeNodeCollection types, TargetNamespaceDictionary targets)
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.VisitModule(ModuleNode module, TargetModule target)
       at Microsoft.FxCop.Engines.Introspection.BaseVisitor.VisitAssembly(AssemblyNode assembly, TargetFile target)
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.VisitAssembly(AssemblyNode assembly, TargetFile target)
       at Microsoft.FxCop.Engines.Introspection.LoadVisitor.Load(TargetFile target, Boolean buildTree, Boolean queueItems, AssemblyNode loadedAssembly)
       at Microsoft.FxCop.Engines.Introspection.IntrospectionAnalysisEngine.LoadTargets(TargetFile target)
       at Microsoft.FxCop.Common.EngineManager.LoadTargets(TargetFile target, Boolean resetCounts, String loadEngine)</InnerStackTrace>
      </Exception>
      <Exception Keyword="CA0052" Kind="Engine">
       <Type>Microsoft.FxCop.Sdk.FxCopException</Type>
       <ExceptionMessage>No targets were selected.</ExceptionMessage>
      </Exception>
     </Exceptions>

     

    For the moment, there are two workarounds:

     

    1) Add a reference to older the version of the assembly. In some cases, such as above where EnvDTE v7 is not shipped, that is not possible.

     

    2) Change the Code Analysis assembly resolving logic as mentioned above.

     

    I've filed a bug on this and in a future service Pack or release, it is likely that we will fix this behavior.

     

    Thank you for bringing this to our attention.

     

    Regards


    David

    Wednesday, November 28, 2007 9:38 PM
    Moderator
  • Thank you for this information, it was been a time saver!
    Wednesday, May 4, 2011 8:24 AM
  • There is another option  instead of modifying the FxCop configuration files.

    Check this one. http://www.paraesthesia.com/archive/2011/04/20/how-to-pass-parameters-to-fxcop-from-visual-studio-or.aspx

    Hope this helps too.

    -Kamal

    Monday, July 18, 2011 6:02 PM