場合によってAutoGenerateBindingRedirects
は(を使用してもGenerateBindingRedirectsOutputType
)十分ではありません。すべてのThere was a conflict
エントリを検索して1つずつ手動で修正するのは面倒な場合があるため、ログ出力を解析して生成する小さなコードを書きました(ダンプ先:) stdout
。
// Paste all "there was a conflict" lines from the msbuild diagnostics log to the file below
const string conflictFile = @"C:\AssemblyConflicts.txt";
var sb = new StringBuilder();
var conflictLines = await File.ReadAllLinesAsync(conflictFile);
foreach (var line in conflictLines.Where(l => !String.IsNullOrWhiteSpace(l)))
{
Console.WriteLine("Processing line: {0}", line);
var lineComponents = line.Split('"');
if (lineComponents.Length < 2)
throw new FormatException("Unexpected conflict line component count");
var assemblySegment = lineComponents[1];
Console.WriteLine("Processing assembly segment: {0}", assemblySegment);
var assemblyComponents = assemblySegment
.Split(",")
.Select(kv => kv.Trim())
.Select(kv => kv.Split("=")
.Last())
.ToArray();
if (assemblyComponents.Length != 4)
throw new FormatException("Unexpected conflict segment component count");
var assembly = assemblyComponents[0];
var version = assemblyComponents[1];
var culture = assemblyComponents[2];
var publicKeyToken = assemblyComponents[3];
Console.WriteLine("Generating assebmly redirect for Assembly={0}, Version={1}, Culture={2}, PublicKeyToken={3}", assembly, version, culture, publicKeyToken);
sb.AppendLine($"<dependentAssembly><assemblyIdentity name=\"{assembly}\" publicKeyToken=\"{publicKeyToken}\" culture=\"{culture}\" /><bindingRedirect oldVersion=\"0.0.0.0-{version}\" newVersion=\"{version}\" /></dependentAssembly>");
}
Console.WriteLine("Generated assembly redirects:");
Console.WriteLine(sb);
ヒント:MSBuild BinaryとStructured Log Viewerを使用して、警告を発するプロジェクト内の競合のバインディングリダイレクトのみを生成します(つまり、there was a conflict
上記のコードの入力テキストファイルへのこれらの行を過ぎて[ AssemblyConflicts.txt
])。