Skip to content

Commit 06cd32d

Browse files
jjonesczgithub-actions
authored andcommitted
Merge all property groups
1 parent 1083b1a commit 06cd32d

File tree

3 files changed

+21
-76
lines changed

3 files changed

+21
-76
lines changed

src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -710,38 +710,31 @@ public static void WriteProjectFile(
710710
writer.WriteLine();
711711
}
712712

713-
// Write default properties unless they are overridden by custom directives.
714-
var propertyDirectiveNames = propertyDirectives.Select(d => d.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
715-
if (!s_defaultProperties.Keys.All(propertyDirectiveNames.Contains))
713+
// Write default and custom properties.
716714
{
717715
writer.WriteLine(" <PropertyGroup>");
716+
717+
// First write the default properties except those specified by the user.
718+
var customPropertyNames = propertyDirectives.Select(d => d.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
718719
foreach (var (name, value) in s_defaultProperties)
719720
{
720-
if (!propertyDirectiveNames.Contains(name))
721+
if (!customPropertyNames.Contains(name))
721722
{
722723
writer.WriteLine($"""
723724
<{name}>{EscapeValue(value)}</{name}>
724725
""");
725726
}
726727
}
727-
writer.WriteLine(" </PropertyGroup>");
728-
writer.WriteLine();
729-
}
730-
731-
if (isVirtualProject)
732-
{
733-
writer.WriteLine("""
734-
<PropertyGroup>
735-
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
736-
</PropertyGroup>
737728

738-
""");
739-
}
740-
741-
if (propertyDirectives.Any())
742-
{
743-
writer.WriteLine(" <PropertyGroup>");
729+
// Write virtual-only properties.
730+
if (isVirtualProject)
731+
{
732+
writer.WriteLine("""
733+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
734+
""");
735+
}
744736

737+
// Write custom properties.
745738
foreach (var property in propertyDirectives)
746739
{
747740
writer.WriteLine($"""
@@ -751,21 +744,18 @@ public static void WriteProjectFile(
751744
processedDirectives++;
752745
}
753746

747+
// Write virtual-only properties which cannot be overridden.
748+
if (isVirtualProject)
749+
{
750+
writer.WriteLine("""
751+
<Features>$(Features);FileBasedProgram</Features>
752+
""");
753+
}
754+
754755
writer.WriteLine(" </PropertyGroup>");
755756
writer.WriteLine();
756757
}
757758

758-
if (isVirtualProject)
759-
{
760-
// After `#:property` directives so they don't override this.
761-
writer.WriteLine("""
762-
<PropertyGroup>
763-
<Features>$(Features);FileBasedProgram</Features>
764-
</PropertyGroup>
765-
766-
""");
767-
}
768-
769759
if (packageDirectives.Any())
770760
{
771761
writer.WriteLine(" <ItemGroup>");

test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,6 @@ public void Directives()
657657
<ImplicitUsings>enable</ImplicitUsings>
658658
<Nullable>enable</Nullable>
659659
<PublishAot>true</PublishAot>
660-
</PropertyGroup>
661-
662-
<PropertyGroup>
663660
<TargetFramework>net472</TargetFramework>
664661
<LangVersion>preview</LangVersion>
665662
</PropertyGroup>
@@ -731,9 +728,6 @@ public void Directives_Variable()
731728
<ImplicitUsings>enable</ImplicitUsings>
732729
<Nullable>enable</Nullable>
733730
<PublishAot>true</PublishAot>
734-
</PropertyGroup>
735-
736-
<PropertyGroup>
737731
<MyProp>MyValue</MyProp>
738732
</PropertyGroup>
739733
@@ -809,9 +803,6 @@ public void Directives_Separators()
809803
<ImplicitUsings>enable</ImplicitUsings>
810804
<Nullable>enable</Nullable>
811805
<PublishAot>true</PublishAot>
812-
</PropertyGroup>
813-
814-
<PropertyGroup>
815806
<Prop1>One=a/b</Prop1>
816807
<Prop2>Two/a=b</Prop2>
817808
</PropertyGroup>
@@ -921,9 +912,6 @@ public void Directives_Escaping()
921912
<ImplicitUsings>enable</ImplicitUsings>
922913
<Nullable>enable</Nullable>
923914
<PublishAot>true</PublishAot>
924-
</PropertyGroup>
925-
926-
<PropertyGroup>
927915
<Prop>&lt;test&quot;&gt;</Prop>
928916
</PropertyGroup>
929917
@@ -958,9 +946,6 @@ public void Directives_Whitespace()
958946
<ImplicitUsings>enable</ImplicitUsings>
959947
<Nullable>enable</Nullable>
960948
<PublishAot>true</PublishAot>
961-
</PropertyGroup>
962-
963-
<PropertyGroup>
964949
<Name>Value</Name>
965950
<NugetPackageDescription>&quot;My package with spaces&quot;</NugetPackageDescription>
966951
</PropertyGroup>
@@ -1005,9 +990,6 @@ public void Directives_AfterToken()
1005990
<ImplicitUsings>enable</ImplicitUsings>
1006991
<Nullable>enable</Nullable>
1007992
<PublishAot>true</PublishAot>
1008-
</PropertyGroup>
1009-
1010-
<PropertyGroup>
1011993
<Prop1>1</Prop1>
1012994
<Prop2>2</Prop2>
1013995
</PropertyGroup>
@@ -1054,9 +1036,6 @@ public void Directives_AfterIf()
10541036
<ImplicitUsings>enable</ImplicitUsings>
10551037
<Nullable>enable</Nullable>
10561038
<PublishAot>true</PublishAot>
1057-
</PropertyGroup>
1058-
1059-
<PropertyGroup>
10601039
<Prop1>1</Prop1>
10611040
<Prop2>2</Prop2>
10621041
</PropertyGroup>
@@ -1100,9 +1079,6 @@ public void Directives_Comments()
11001079
<ImplicitUsings>enable</ImplicitUsings>
11011080
<Nullable>enable</Nullable>
11021081
<PublishAot>true</PublishAot>
1103-
</PropertyGroup>
1104-
1105-
<PropertyGroup>
11061082
<Prop1>1</Prop1>
11071083
<Prop2>2</Prop2>
11081084
</PropertyGroup>

test/dotnet.Tests/CommandTests/Run/RunFileTests.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,18 +1861,9 @@ public void Api()
18611861
<ImplicitUsings>enable</ImplicitUsings>
18621862
<Nullable>enable</Nullable>
18631863
<PublishAot>true</PublishAot>
1864-
</PropertyGroup>
1865-
1866-
<PropertyGroup>
18671864
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
1868-
</PropertyGroup>
1869-
1870-
<PropertyGroup>
18711865
<TargetFramework>net11.0</TargetFramework>
18721866
<LangVersion>preview</LangVersion>
1873-
</PropertyGroup>
1874-
1875-
<PropertyGroup>
18761867
<Features>$(Features);FileBasedProgram</Features>
18771868
</PropertyGroup>
18781869
@@ -1939,13 +1930,7 @@ public void Api_Diagnostic_01()
19391930
<ImplicitUsings>enable</ImplicitUsings>
19401931
<Nullable>enable</Nullable>
19411932
<PublishAot>true</PublishAot>
1942-
</PropertyGroup>
1943-
1944-
<PropertyGroup>
19451933
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
1946-
</PropertyGroup>
1947-
1948-
<PropertyGroup>
19491934
<Features>$(Features);FileBasedProgram</Features>
19501935
</PropertyGroup>
19511936
@@ -2011,13 +1996,7 @@ public void Api_Diagnostic_02()
20111996
<ImplicitUsings>enable</ImplicitUsings>
20121997
<Nullable>enable</Nullable>
20131998
<PublishAot>true</PublishAot>
2014-
</PropertyGroup>
2015-
2016-
<PropertyGroup>
20171999
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2018-
</PropertyGroup>
2019-
2020-
<PropertyGroup>
20212000
<Features>$(Features);FileBasedProgram</Features>
20222001
</PropertyGroup>
20232002

0 commit comments

Comments
 (0)