Made some fixes to binding redirects
- Don't generate an empty config file with no redirects. - Fix swapped publicKeyToken and culture #462
This commit is contained in:
parent
d09137f8d5
commit
7d2277d930
2 changed files with 23 additions and 8 deletions
|
@ -36,11 +36,19 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
public XDocument Generate(IEnumerable<LibraryExport> dependencies)
|
public XDocument Generate(IEnumerable<LibraryExport> dependencies)
|
||||||
{
|
{
|
||||||
|
var redirects = CollectRedirects(dependencies);
|
||||||
|
|
||||||
|
if (!redirects.Any())
|
||||||
|
{
|
||||||
|
// No redirects required
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var document = new XDocument(
|
var document = new XDocument(
|
||||||
new XElement(ConfigurationElementName,
|
new XElement(ConfigurationElementName,
|
||||||
new XElement(RuntimeElementName,
|
new XElement(RuntimeElementName,
|
||||||
new XElement(AssemblyBindingElementName,
|
new XElement(AssemblyBindingElementName,
|
||||||
CollectRedirects(dependencies).Select(GetDependentAssembly)
|
redirects.Select(GetDependentAssembly)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -108,8 +116,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
var identity = new AssemblyIdentity(
|
var identity = new AssemblyIdentity(
|
||||||
metadataReader.GetString(definition.Name),
|
metadataReader.GetString(definition.Name),
|
||||||
definition.Version,
|
definition.Version,
|
||||||
publicKeyToken,
|
metadataReader.GetString(definition.Culture),
|
||||||
metadataReader.GetString(definition.Culture)
|
publicKeyToken
|
||||||
);
|
);
|
||||||
|
|
||||||
var references = new List<AssemblyIdentity>(metadataReader.AssemblyReferences.Count);
|
var references = new List<AssemblyIdentity>(metadataReader.AssemblyReferences.Count);
|
||||||
|
@ -120,8 +128,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
references.Add(new AssemblyIdentity(
|
references.Add(new AssemblyIdentity(
|
||||||
metadataReader.GetString(assemblyReference.Name),
|
metadataReader.GetString(assemblyReference.Name),
|
||||||
assemblyReference.Version,
|
assemblyReference.Version,
|
||||||
GetPublicKeyToken(metadataReader.GetBlobBytes(assemblyReference.PublicKeyOrToken)),
|
metadataReader.GetString(assemblyReference.Culture),
|
||||||
metadataReader.GetString(assemblyReference.Culture)
|
GetPublicKeyToken(metadataReader.GetBlobBytes(assemblyReference.PublicKeyOrToken))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -496,6 +496,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
{
|
{
|
||||||
CopyExport(outputPath, export);
|
CopyExport(outputPath, export);
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateBindingRedirects(runtimeContext, outputPath, exporter);
|
GenerateBindingRedirects(runtimeContext, outputPath, exporter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -508,12 +509,18 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
{
|
{
|
||||||
var generator = new BindingRedirectGenerator();
|
var generator = new BindingRedirectGenerator();
|
||||||
var config = generator.Generate(exporter.GetAllExports());
|
var config = generator.Generate(exporter.GetAllExports());
|
||||||
|
|
||||||
|
if (config != null)
|
||||||
|
{
|
||||||
|
// TODO: Handle existing App.config file transformation
|
||||||
|
// We have something to generate
|
||||||
var path = Path.Combine(outputPath, runtimeContext.ProjectFile.Name + ".exe.config");
|
var path = Path.Combine(outputPath, runtimeContext.ProjectFile.Name + ".exe.config");
|
||||||
using (var stream = File.Create(path))
|
using (var stream = File.Create(path))
|
||||||
{
|
{
|
||||||
config.Save(stream);
|
config.Save(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void CopyExport(string outputPath, LibraryExport export)
|
private static void CopyExport(string outputPath, LibraryExport export)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue