Secret Manager: Save project file without XML declaration (#14354)
This commit is contained in:
parent
853d8f02e7
commit
e937884eb4
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using System.Xml.XPath;
|
using System.Xml.XPath;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
@ -122,7 +123,16 @@ namespace Microsoft.Extensions.SecretManager.Tools.Internal
|
||||||
propertyGroup.Add(new XElement("UserSecretsId", newSecretsId));
|
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));
|
context.Reporter.Output(Resources.FormatMessage_SetUserSecretsIdForProject(newSecretsId, projectPath));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.Extensions.Configuration.UserSecrets.Tests;
|
using Microsoft.Extensions.Configuration.UserSecrets.Tests;
|
||||||
using Microsoft.Extensions.SecretManager.Tools.Internal;
|
using Microsoft.Extensions.SecretManager.Tools.Internal;
|
||||||
|
|
@ -90,6 +91,18 @@ namespace Microsoft.Extensions.SecretManager.Tools.Tests
|
||||||
Assert.Equal(SecretId, idResolver.Resolve(null, null));
|
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]
|
[Fact]
|
||||||
public void OverridesIdForProjectWithSecretId()
|
public void OverridesIdForProjectWithSecretId()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue