本文整理汇总了C#中IAnalyzerAssemblyLoader.AddDependencyLocation方法的典型用法代码示例。如果您正苦于以下问题:C# IAnalyzerAssemblyLoader.AddDependencyLocation方法的具体用法?C# IAnalyzerAssemblyLoader.AddDependencyLocation怎么用?C# IAnalyzerAssemblyLoader.AddDependencyLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAnalyzerAssemblyLoader
的用法示例。
在下文中一共展示了IAnalyzerAssemblyLoader.AddDependencyLocation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveAnalyzersFromArguments
internal ImmutableArray<DiagnosticAnalyzer> ResolveAnalyzersFromArguments(
string language,
List<DiagnosticInfo> diagnostics,
CommonMessageProvider messageProvider,
IAnalyzerAssemblyLoader analyzerLoader)
{
var analyzerBuilder = ImmutableArray.CreateBuilder<DiagnosticAnalyzer>();
EventHandler<AnalyzerLoadFailureEventArgs> errorHandler = (o, e) =>
{
var analyzerReference = o as AnalyzerFileReference;
DiagnosticInfo diagnostic;
switch (e.ErrorCode)
{
case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToLoadAnalyzer:
diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_UnableToLoadAnalyzer, analyzerReference.FullPath, e.Message);
break;
case AnalyzerLoadFailureEventArgs.FailureErrorCode.UnableToCreateAnalyzer:
diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_AnalyzerCannotBeCreated, e.TypeName, analyzerReference.FullPath, e.Message);
break;
case AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers:
diagnostic = new DiagnosticInfo(messageProvider, messageProvider.WRN_NoAnalyzerInAssembly, analyzerReference.FullPath);
break;
case AnalyzerLoadFailureEventArgs.FailureErrorCode.None:
default:
return;
}
// Filter this diagnostic based on the compilation options so that /nowarn and /warnaserror etc. take effect.
diagnostic = messageProvider.FilterDiagnosticInfo(diagnostic, this.CompilationOptions);
if (diagnostic != null)
{
diagnostics.Add(diagnostic);
}
};
var resolvedReferences = ArrayBuilder<AnalyzerFileReference>.GetInstance();
foreach (var reference in AnalyzerReferences)
{
var resolvedReference = ResolveAnalyzerReference(reference, analyzerLoader);
if (resolvedReference != null)
{
resolvedReferences.Add(resolvedReference);
// register the reference to the analyzer loader:
analyzerLoader.AddDependencyLocation(resolvedReference.FullPath);
}
else
{
diagnostics.Add(new DiagnosticInfo(messageProvider, messageProvider.ERR_MetadataFileNotFound, reference.FilePath));
}
}
// All analyzer references are registered now, we can start loading them:
foreach (var resolvedReference in resolvedReferences)
{
resolvedReference.AnalyzerLoadFailed += errorHandler;
resolvedReference.AddAnalyzers(analyzerBuilder, language);
resolvedReference.AnalyzerLoadFailed -= errorHandler;
}
resolvedReferences.Free();
return analyzerBuilder.ToImmutable();
}
示例2: CheckCore
private static bool CheckCore(string baseDirectory, IEnumerable<CommandLineAnalyzerReference> analyzerReferences, IAnalyzerAssemblyLoader loader, IEnumerable<string> ignorableReferenceNames)
{
var resolvedPaths = new List<string>();
foreach (var analyzerReference in analyzerReferences)
{
string resolvedPath = FileUtilities.ResolveRelativePath(analyzerReference.FilePath, basePath: null, baseDirectory: baseDirectory, searchPaths: SpecializedCollections.EmptyEnumerable<string>(), fileExists: File.Exists);
if (File.Exists(resolvedPath))
{
resolvedPath = FileUtilities.TryNormalizeAbsolutePath(resolvedPath);
if (resolvedPath != null)
{
resolvedPaths.Add(resolvedPath);
}
}
// Don't worry about paths we can't resolve. The compiler will report an error for that later.
}
// First, check that the set of references is complete, modulo items in the safe list.
foreach (var resolvedPath in resolvedPaths)
{
var missingDependencies = AssemblyUtilities.IdentifyMissingDependencies(resolvedPath, resolvedPaths);
foreach (var missingDependency in missingDependencies)
{
if (!ignorableReferenceNames.Any(name => missingDependency.Name.StartsWith(name)))
{
CompilerServerLogger.Log($"Analyzer assembly {resolvedPath} depends on '{missingDependency}' but it was not found.");
return false;
}
}
}
// Second, load all of the assemblies upfront.
foreach (var resolvedPath in resolvedPaths)
{
loader.AddDependencyLocation(resolvedPath);
}
var loadedAssemblies = new List<Assembly>();
foreach (var resolvedPath in resolvedPaths)
{
loadedAssemblies.Add(loader.LoadFromPath(resolvedPath));
}
// Third, check that the MVIDs of the files on disk match the MVIDs of the loaded assemblies.
for (int i = 0; i < resolvedPaths.Count; i++)
{
var resolvedPath = resolvedPaths[i];
var loadedAssembly = loadedAssemblies[i];
var resolvedPathMvid = AssemblyUtilities.ReadMvid(resolvedPath);
var loadedAssemblyMvid = loadedAssembly.ManifestModule.ModuleVersionId;
if (resolvedPathMvid != loadedAssemblyMvid)
{
CompilerServerLogger.Log($"Analyzer assembly {resolvedPath} has MVID '{resolvedPathMvid}' but loaded assembly '{loadedAssembly.FullName}' has MVID '{loadedAssemblyMvid}'.");
return false;
}
}
return true;
}