Secret Manager: Save project file without XML declaration (#14354)

This commit is contained in:
Scott Addie 2020-02-19 12:25:28 -06:00 committed by GitHub
parent 853d8f02e7
commit e937884eb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using Microsoft.Extensions.CommandLineUtils;
@ -122,7 +123,16 @@ namespace Microsoft.Extensions.SecretManager.Tools.Internal
propertyGroup.Add(new XElement("UserSecretsId", newSecretsId));
}
projectDocument.Save(projectPath);
var settings = new XmlWriterSettings
{
Indent = true,
OmitXmlDeclaration = true,
};
using (var xw = XmlWriter.Create(projectPath, settings))
{
projectDocument.Save(xw);
}
context.Reporter.Output(Resources.FormatMessage_SetUserSecretsIdForProject(newSecretsId, projectPath));
}

View File

@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Text;
using System.Xml.Linq;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Configuration.UserSecrets.Tests;
using Microsoft.Extensions.SecretManager.Tools.Internal;
@ -90,6 +91,18 @@ namespace Microsoft.Extensions.SecretManager.Tools.Tests
Assert.Equal(SecretId, idResolver.Resolve(null, null));
}
[Fact]
public void DoesNotAddXmlDeclarationToProject()
{
var projectDir = _fixture.CreateProject(null);
var projectFile = Path.Combine(projectDir, "TestProject.csproj");
new InitCommand(null, null).Execute(MakeCommandContext(), projectDir);
var projectDocument = XDocument.Load(projectFile);
Assert.Null(projectDocument.Declaration);
}
[Fact]
public void OverridesIdForProjectWithSecretId()
{