Compilation.GetUsedAssemblyReferences(CancellationToken) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Unique metadata assembly references that are considered to be used by this compilation. For example, if a type declared in a referenced assembly is referenced in source code within this compilation, the reference is considered to be used. Etc. The returned set is a subset of references returned by References API. The result is undefined if the compilation contains errors.
The effect of imported namespaces on result of this API depends on whether reporting of unused imports is disabled for the compilation. The reporting of unused imports is disabled if DocumentationMode is set to None.
When unused imports reporting is disabled, all referenced assemblies containing any types that belong to imported namespaces are included in the result. I.e. considered used.
When unused imports reporting is enabled, imported namespaces do not have effect on the result of this API. Therefore, removing assembly references that aren't in the result, could potentially cause error "CS0246: The type or namespace name could not be found (are you missing a using directive or an assembly reference?)" on an unused namespace import. However, that import would be reported by compiler as unused for the compilation on which this API was invoked. In order to avoid the errors, it is recommended to remove unused assembly references and unused imports at the same time.
public abstract System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.MetadataReference> GetUsedAssemblyReferences (System.Threading.CancellationToken cancellationToken = default);
abstract member GetUsedAssemblyReferences : System.Threading.CancellationToken -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.MetadataReference>
Public MustOverride Function GetUsedAssemblyReferences (Optional cancellationToken As CancellationToken = Nothing) As ImmutableArray(Of MetadataReference)
Parameters
- cancellationToken
- CancellationToken