private void CheckAppConfigFiles(IEnumerable <string> appConfigFiles) { foreach (var appConfigFilePath in appConfigFiles) { var appConfigFile = AppConfigFile.Read(appConfigFilePath); if (appConfigFile.Errors.Any()) { foreach (var error in appConfigFile.Errors) { Log($"In app.config file {appConfigFilePath}: {error}"); } return; } foreach (var bindingRedirect in appConfigFile.BindingRedirects) { CheckBindingRedirect( appConfigFilePath, bindingRedirect.Name, bindingRedirect.PublicKeyToken, bindingRedirect.OldVersionRangeStart, bindingRedirect.OldVersionRangeEnd, bindingRedirect.NewVersion); } } }
private void CheckAppConfigFiles(IEnumerable <string> appConfigFiles) { var versionMismatchesByName = versionMismatches .ToLookup(mismatch => mismatch.ExpectedReference.Name, StringComparer.OrdinalIgnoreCase) .ToDictionary(kvp => kvp.Key, kvp => kvp.ToList(), StringComparer.OrdinalIgnoreCase); foreach (var appConfigFilePath in appConfigFiles) { var appConfigFileName = Path.GetFileName(appConfigFilePath); var appConfigFile = AppConfigFile.Read(appConfigFilePath); if (appConfigFile.Errors.Any()) { foreach (var error in appConfigFile.Errors) { diagnostics.Add($"In app.config file {appConfigFileName}: {error}"); } } foreach (var bindingRedirect in appConfigFile.BindingRedirects) { CheckBindingRedirect( appConfigFileName, bindingRedirect.Name, bindingRedirect.PublicKeyToken, bindingRedirect.OldVersionRangeStart, bindingRedirect.OldVersionRangeEnd, bindingRedirect.NewVersion, versionMismatchesByName); } } foreach (var versionMismatch in versionMismatchesByName.Values.SelectMany(list => list)) { string referencedFullName = versionMismatch.ExpectedReference.FullName; if (referencedFullName.StartsWith("netstandard,")) { continue; } string actualFilePath = versionMismatch.ActualAssembly.MainModule.FileName; if (actualFilePath.Contains("Mono.framework")) { continue; } if (actualFilePath.StartsWith(rootDirectory)) { actualFilePath = actualFilePath.Substring(rootDirectory.Length); if (actualFilePath.StartsWith("\\") || actualFilePath.StartsWith("/")) { actualFilePath = actualFilePath.Substring(1); } } diagnostics.Add($"Assembly {versionMismatch.Referencer.Name.Name} is referencing {referencedFullName} but found {versionMismatch.ActualAssembly.FullName} at {actualFilePath}"); } }
public static AppConfigFile Read(string filePath) { var appConfigFile = new AppConfigFile(filePath); try { appConfigFile.Parse(filePath); } catch (Exception ex) { appConfigFile.errors.Add(ex.Message); } return(appConfigFile); }
private void CheckAppConfigFiles(IEnumerable <string> appConfigFiles) { var versionMismatchesByName = versionMismatches .ToLookup(mismatch => mismatch.ExpectedReference.Name, StringComparer.OrdinalIgnoreCase) .ToDictionary(kvp => kvp.Key, kvp => kvp.ToList(), StringComparer.OrdinalIgnoreCase); foreach (var appConfigFilePath in appConfigFiles) { var appConfigFileName = Path.GetFileName(appConfigFilePath); var appConfigFile = AppConfigFile.Read(appConfigFilePath); if (appConfigFile.Errors.Any()) { foreach (var error in appConfigFile.Errors) { diagnostics.Add($"In app.config file {appConfigFileName}: {error}"); } continue; } foreach (var bindingRedirect in appConfigFile.BindingRedirects) { CheckBindingRedirect( appConfigFileName, bindingRedirect.Name, bindingRedirect.PublicKeyToken, bindingRedirect.OldVersionRangeStart, bindingRedirect.OldVersionRangeEnd, bindingRedirect.NewVersion, versionMismatchesByName); } } foreach (var versionMismatch in versionMismatchesByName.Values.SelectMany(list => list)) { diagnostics.Add($"Assembly {versionMismatch.Referencer.Name.Name} is referencing {versionMismatch.ExpectedReference.FullName} but found {versionMismatch.ActualAssembly.FullName} at {versionMismatch.ActualAssembly.MainModule.FileName}"); } }