Managing Target Assemblies

FxCop analyzes managed code executables and DLLs, called target assemblies. At least one target assembly must be added to the current project before an analysis can be run; multiple target assemblies can be included in a single analysis. A target for analysis can be an assembly, module, namespace, type, type member, parameter, or resource.

You can exclude targets from analysis temporarily, or you can remove a target assembly from a project entirely. If a target is excluded from analysis, it remains on the Targets tab in the configuration pane, but it is not included in analysis reports. If you remove a target assembly from a project, it no longer appears on the Targets tab and any messages associated with the target are deleted. Once a target assembly is removed, it must be added to the project again before it can be included in an analysis.

In This Section

Adding Target Assemblies

Ignoring Targets During Analysis

Removing Target Assemblies from a Project

Specifying a Location for a Target Assembly using Environment Variables

Viewing Metadata and MSIL

Adding Target Assemblies

One or more target assemblies must be specified for analysis. First, open a new or existing project, and then add target assemblies (.exe or .dll files) using either of the following procedures.

To drag a target assembly into the current project

  1. Click the Targets tab in the configuration pane.

  2. From a file viewer, such as Microsoft® Windows Explorer, drag the file or files to be added into the configuration pane.

To add a target assembly to the current project

  1. From the Project menu, select Add Targets.

  2. Browse to the target to add.

  3. Click Open.

FxCop adds the target assembly to the current project with all its types and type members enabled. If you do not want to include all the target assembly's types and members, you must disable them. For more information, see Ignoring Targets During Analysis.

Target Load Errors

If any errors are encountered, the Error(s) Loading Assemblies dialog box appears, listing the assemblies that could not be loaded and the reasons why. Double-click one of the list items to display the AssemblyLoadException Details dialog box, which provides the information shown in the following table, if available.

Detail item Description

FileName

The name of the assembly that could not be loaded.

HelpLink

A link to the Help file associated with the exception.

InnerException

The inner exception that is contained in the exception.

InnerExceptions

All inner exceptions.

When this cell is selected, ellipses appear in the cell. Clicking the ellipses displays the Exception Collection Editor dialog box. This dialog box is not part of the functionality of FxCop.

Message

The reason the assembly did not load.

Source

The FxCop assembly that generated the exception.

StackTrace

The stack trace associated with the exception.

TargetSite

The FxCop member that generated the exception.

Delay-Signed Assemblies

When you try to add a delay-signed assembly, FxCop reports the following error:

Strong name validation failed for assembly 'SomeAssemblyName'

The .NET Framework cannot verify the signature of a delay-signed assembly, and therefore considers it unsafe to load. A delay-signed assembly will not load unless you disable signature verification for the assembly by using the Strong Name command-line tool (Sn.exe) that is included with the .NET Framework. To disable verification of the delay-signed assembly, type the following at the command line:

SN -Vr SomeAssemblyName

This allows the assembly named SomeAssemblyName to skip verification. After an assembly is registered in this manner, the common language runtime will not try to verify the signature. Currently running instances of FxCop will not detect the new registration; you must exit the application and start it again to load the assembly.

NoteNote

Disabling verification of an assembly creates a security vulnerability. To re-enable verification of the assembly, type the following at the command line:

SN -Vu SomeAssemblyName

For more information, see the following topics on MSDN:

Ignoring Targets During Analysis

You ignore a target assembly, type, or type member during analysis by clearing the check box next to the target name, which also clears the selection from all child nodes. An ignored target remains on the Targets tab in the configuration pane and messages relevant to it remain in the messages pane and are written to any saved reports. On subsequent analyses, the targets that are not selected are ignored and therefore do not produce any messages. For information about how to permanently remove a target assembly from the Assemblies list, see Removing Target Assemblies from a Project.

To ignore a target and all its child nodes

  1. Click the Targets tab in the configuration pane.

  2. Expand the tree view, if necessary.

  3. Clear the check box next to the target name.

To include an ignored target and all its child nodes, select the check box again.

NoteNote

Any changes that you made to the Targets tab are not retained in the project file until you save the project.

For information about how to remove a target assembly from the Assemblies list, see Removing Target Assemblies from a Project.

Removing Target Assemblies from a Project

You can ignore a target assembly, type, or type member during analysis, or you can remove a target assembly from the current project entirely. When you remove an assembly from the current project, it no longer appears on the Targets tab in the configuration pane. It must be added to the project again to be included in an analysis. If an assembly is removed, any report messages generated for targets within the assembly are also removed from the project.

To remove an assembly from the current project

  1. Click the Targets tab in the configuration pane.

  2. Select the target assembly to be removed by clicking its name.

  3. From the Edit menu, choose Remove File.

You can also right-click the assembly to be removed, and choose Remove.

For information about how to temporarily ignore an assembly, see Ignoring Targets During Analysis.

Specifying a Location for a Target Assembly using Environment Variables

You can specify the location a target assembly is subsequently loaded from using a path that includes environment variables. FxCop reads environment variables when the application is started. Any changes to environment variables are ignored until FxCop is shut down and restarted.

To specify the location using environment variables

  1. Click the Targets tab in the configuration pane.

  2. Right-click the target assembly and select Properties.

  3. Type the location in the Save Name box.

NoteNote

Using environment variables for the location of an assembly can result in the assembly failing to load if the environment variables are not initialized. This might require manually editing the project file to correct. As an alternative to environment variables, consider using a Shared Project, which can be found in the "Shared Project" section of the topic Managing FxCop Projects.

Viewing Metadata and MSIL

Metadata and Microsoft intermediate language (MSIL) can be displayed for targets that are loaded in FxCop.

To view metadata

  1. Click the Targets tab in the configuration pane.

  2. Expand the assembly and subnodes.

  3. Select the target element.

The metadata appears in the properties pane.

  1. Right-click the target element, choose View, and then choose IL.

A window appears that displays the MSIL.