Read original app.config and add to it

This commit is contained in:
Pavel Krymets 2015-12-10 08:58:18 -08:00
parent 1115fc22fa
commit 91acc03a13
2 changed files with 81 additions and 35 deletions

View file

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Dnx.Runtime.Common.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli.Compiler.Common;
@ -507,17 +507,32 @@ namespace Microsoft.DotNet.Tools.Compiler
private static void GenerateBindingRedirects(ProjectContext runtimeContext, string outputPath, LibraryExporter exporter)
{
var generator = new BindingRedirectGenerator();
var config = generator.Generate(exporter.GetAllExports());
var appConfigNames = new[] { "app.config", "App.config" };
XDocument baseAppConfig = null;
if (config != null)
foreach (var appConfigName in appConfigNames)
{
var baseAppConfigPath = Path.Combine(runtimeContext.ProjectDirectory, appConfigName);
if (File.Exists(baseAppConfigPath))
{
using (var fileStream = File.OpenRead(baseAppConfigPath))
{
baseAppConfig = XDocument.Load(fileStream);
break;
}
}
}
var generator = new BindingRedirectGenerator();
var appConfig = generator.Generate(exporter.GetAllExports(), baseAppConfig);
if (appConfig != null)
{
// TODO: Handle existing App.config file transformation
// We have something to generate
var path = Path.Combine(outputPath, runtimeContext.ProjectFile.Name + ".exe.config");
using (var stream = File.Create(path))
{
config.Save(stream);
appConfig.Save(stream);
}
}
}