Skip to content

Commit

Permalink
allow for various xml formatting when finding runtime config file (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored Oct 11, 2024
1 parent fc31ae6 commit 5aeff3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,20 @@ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
);
}

[Fact]
public async Task UpdateBindingRedirectInWebConfig()
// the xml can take various shapes and they're all formatted, so we need very specific values here
[Theory]
[InlineData("<Content Include=\"web.config\" />")]
[InlineData("<Content Include=\"web.config\">\n </Content>")]
[InlineData("<Content Include=\"web.config\">\n <SubType>Designer</SubType>\n </Content>")]
public async Task UpdateBindingRedirectInWebConfig(string webConfigXml)
{
await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
packages:
[
MockNuGetPackage.CreatePackageWithAssembly("Some.Package", "7.0.1", "net45", "7.0.0.0"),
MockNuGetPackage.CreatePackageWithAssembly("Some.Package", "13.0.1", "net45", "13.0.0.0"),
],
projectContents: """
projectContents: $$"""
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -669,7 +673,7 @@ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Content Include="web.config" />
{{webConfigXml}}
<Content Include="web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</Content>
Expand Down Expand Up @@ -711,7 +715,7 @@ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
</configuration>
""")
],
expectedProjectContents: """
expectedProjectContents: $$"""
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -768,7 +772,7 @@ await TestUpdateForProject("Some.Package", "7.0.1", "13.0.1",
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Content Include="web.config" />
{{webConfigXml}}
<Content Include="web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ static void AddConfigFileToProject(ProjectBuildFile projectBuildFile, Configurat
return null;
}

var configFilePath = Path.GetFullPath(Path.Combine(directoryPath, GetContent(configFile)));
var configFilePath = Path.GetFullPath(Path.Combine(directoryPath, GetValue(configFile)));
var configFileContents = await File.ReadAllTextAsync(configFilePath);
return new ConfigurationFile(configFilePath, configFileContents, false);

static string GetContent(IXmlElementSyntax element)
static string GetValue(IXmlElementSyntax element)
{
var content = element.GetContentValue();
var content = element.GetAttributeValue("Include");
if (!string.IsNullOrEmpty(content))
{
return content;
}

content = element.GetAttributeValue("Include");
content = element.GetContentValue();
if (!string.IsNullOrEmpty(content))
{
return content;
Expand All @@ -139,7 +139,7 @@ static string GetContent(IXmlElementSyntax element)

static bool IsConfigFile(IXmlElementSyntax element)
{
var content = GetContent(element);
var content = GetValue(element);
if (content is null)
{
return false;
Expand Down

0 comments on commit 5aeff3f

Please sign in to comment.