Skip to content

Commit 61583eb

Browse files
authored
light up container publish for all Exe/WinExe projects by default (#47064)
1 parent 3d4bbc3 commit 61583eb

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

src/Containers/packaging/build/Microsoft.NET.Build.Containers.targets

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<_ContainerIsTargetingNet8TFM Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '8.0'))">true</_ContainerIsTargetingNet8TFM>
1616
<_ContainerIsSelfContained>false</_ContainerIsSelfContained>
1717
<_ContainerIsSelfContained Condition="'$(SelfContained)' == 'true' or '$(PublishSelfContained)' == 'true'">true</_ContainerIsSelfContained>
18+
19+
<EnableSdkContainerSupport Condition="'$(EnableSdkContainerSupport)' == '' and '$(OutputType)' != 'Library'" >true</EnableSdkContainerSupport>
1820
</PropertyGroup>
1921

2022
<ItemGroup>
@@ -235,10 +237,6 @@
235237
)"
236238
Code="CONTAINER005"
237239
Text="The $(_ContainersPackageIdentity) NuGet package is explicitly referenced but the current SDK can natively publish the project as a container. Consider removing the package reference to $(_ContainersPackageIdentity) because it is no longer needed." />
238-
239-
<PropertyGroup>
240-
<EnableSdkContainerSupport Condition="'@(ContainersPackage)' != ''">true</EnableSdkContainerSupport>
241-
</PropertyGroup>
242240
</Target>
243241

244242
<Target Name="_PublishSingleContainer"

test/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,10 @@ public async Task EndToEnd_MultiProjectSolution()
407407
.Execute()
408408
.Should().Pass();
409409

410-
// Add 'EnableSdkContainerSupport' property to the ConsoleApp and set TFM
410+
// set TFM for the console app
411411
using (FileStream stream = File.Open(Path.Join(newSolutionDir.FullName, "ConsoleApp", "ConsoleApp.csproj"), FileMode.Open, FileAccess.ReadWrite))
412412
{
413413
XDocument document = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None);
414-
document
415-
.Descendants()
416-
.First(e => e.Name.LocalName == "PropertyGroup")?
417-
.Add(new XElement("EnableSdkContainerSupport", "true"));
418414
document
419415
.Descendants()
420416
.First(e => e.Name.LocalName == "TargetFramework")
@@ -452,6 +448,8 @@ public async Task EndToEnd_MultiProjectSolution()
452448
[InlineData("webapi", true)]
453449
[InlineData("worker", false)]
454450
[InlineData("worker", true)]
451+
[InlineData("console", true)]
452+
[InlineData("console", false)]
455453
public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackageReference)
456454
{
457455
DirectoryInfo newProjectDir = new(Path.Combine(TestSettings.TestArtifactsDirectory, $"CreateNewImageTest_{projectType}_{addPackageReference}"));
@@ -503,7 +501,6 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
503501
var project = XDocument.Load(projectPath);
504502
var ns = project.Root?.Name.Namespace ?? throw new InvalidOperationException("Project file is empty");
505503

506-
project.Root?.Add(new XElement("PropertyGroup", new XElement("EnableSDKContainerSupport", "true")));
507504
project.Save(projectPath);
508505
}
509506

@@ -677,8 +674,7 @@ public void EndToEnd_NoAPI_Console(string baseImage)
677674
$"/p:ContainerBaseImage={baseImage}",
678675
$"/p:ContainerRegistry={DockerRegistryManager.LocalRegistry}",
679676
$"/p:ContainerRepository={imageName}",
680-
$"/p:ContainerImageTag={imageTag}",
681-
"/p:EnableSdkContainerSupport=true")
677+
$"/p:ContainerImageTag={imageTag}")
682678
.WithEnvironmentVariable("NUGET_PACKAGES", privateNuGetAssets.FullName)
683679
.WithWorkingDirectory(newProjectDir.FullName)
684680
.Execute()
@@ -718,8 +714,7 @@ public void EndToEnd_SingleArch_NoRid()
718714
"/t:PublishContainer",
719715
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
720716
$"/p:ContainerRepository={imageName}",
721-
$"/p:ContainerImageTag={imageTag}",
722-
"/p:EnableSdkContainerSupport=true")
717+
$"/p:ContainerImageTag={imageTag}")
723718
.WithWorkingDirectory(newProjectDir.FullName)
724719
.Execute();
725720
commandResult.Should().Pass();
@@ -754,8 +749,7 @@ public void EndToEndMultiArch_LocalRegistry(string imageName)
754749
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
755750
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
756751
$"/p:ContainerRepository={imageName}",
757-
$"/p:ContainerImageTag={tag}",
758-
"/p:EnableSdkContainerSupport=true")
752+
$"/p:ContainerImageTag={tag}")
759753
.WithWorkingDirectory(newProjectDir.FullName)
760754
.Execute();
761755

@@ -818,7 +812,6 @@ public void MultiArchStillAllowsSingleRID()
818812
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
819813
$"/p:ContainerRepository={imageName}",
820814
$"/p:ContainerImageTag={imageTag}",
821-
"/p:EnableSdkContainerSupport=true",
822815
"/bl")
823816
.WithWorkingDirectory(newProjectDir.FullName)
824817
.Execute();
@@ -868,7 +861,6 @@ public void MultiArchStillAllowsSingleRIDUsingJustRIDProperties()
868861
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
869862
$"/p:ContainerRepository={imageName}",
870863
$"/p:ContainerImageTag={imageTag}",
871-
"/p:EnableSdkContainerSupport=true",
872864
"/bl")
873865
.WithWorkingDirectory(newProjectDir.FullName)
874866
.Execute();
@@ -941,8 +933,7 @@ public void EndToEndMultiArch_ArchivePublishing(string imageName)
941933
$"/p:ContainerArchiveOutputPath={archiveOutput}",
942934
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
943935
$"/p:ContainerRepository={imageName}",
944-
$"/p:ContainerImageTag={tag}",
945-
"/p:EnableSdkContainerSupport=true")
936+
$"/p:ContainerImageTag={tag}")
946937
.WithWorkingDirectory(newProjectDir.FullName)
947938
.Execute();
948939

@@ -1012,8 +1003,7 @@ public void EndToEndMultiArch_RemoteRegistry()
10121003
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
10131004
$"/p:ContainerRegistry={registry}",
10141005
$"/p:ContainerRepository={imageName}",
1015-
$"/p:ContainerImageTag={imageTag}",
1016-
"/p:EnableSdkContainerSupport=true")
1006+
$"/p:ContainerImageTag={imageTag}")
10171007
.WithWorkingDirectory(newProjectDir.FullName)
10181008
.Execute();
10191009

@@ -1044,7 +1034,7 @@ public void EndToEndMultiArch_RemoteRegistry()
10441034
imageFromRegistry)
10451035
.Execute()
10461036
.Should().Pass();
1047-
1037+
10481038
// Run the containers
10491039
ContainerCli.RunCommand(
10501040
_testOutput,
@@ -1087,8 +1077,7 @@ public void EndToEndMultiArch_ContainerRuntimeIdentifiersOverridesRuntimeIdentif
10871077
"/p:ContainerRuntimeIdentifiers=linux-arm64",
10881078
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
10891079
$"/p:ContainerRepository={imageName}",
1090-
$"/p:ContainerImageTag={imageTag}",
1091-
"/p:EnableSdkContainerSupport=true")
1080+
$"/p:ContainerImageTag={imageTag}")
10921081
.WithWorkingDirectory(newProjectDir.FullName)
10931082
.Execute();
10941083

@@ -1138,8 +1127,7 @@ public void EndToEndMultiArch_EnvVariables()
11381127
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
11391128
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
11401129
$"/p:ContainerRepository={imageName}",
1141-
$"/p:ContainerImageTag={tag}",
1142-
"/p:EnableSdkContainerSupport=true")
1130+
$"/p:ContainerImageTag={tag}")
11431131
.WithWorkingDirectory(newProjectDir.FullName)
11441132
.Execute()
11451133
.Should().Pass();
@@ -1203,8 +1191,7 @@ public void EndToEndMultiArch_Ports()
12031191
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
12041192
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
12051193
$"/p:ContainerRepository={imageName}",
1206-
$"/p:ContainerImageTag={tag}",
1207-
"/p:EnableSdkContainerSupport=true")
1194+
$"/p:ContainerImageTag={tag}")
12081195
.WithWorkingDirectory(newProjectDir.FullName)
12091196
.Execute()
12101197
.Should().Pass();
@@ -1290,8 +1277,7 @@ public void EndToEndMultiArch_Labels()
12901277
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
12911278
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
12921279
$"/p:ContainerRepository={imageName}",
1293-
$"/p:ContainerImageTag={tag}",
1294-
"/p:EnableSdkContainerSupport=true")
1280+
$"/p:ContainerImageTag={tag}")
12951281
.WithWorkingDirectory(newProjectDir.FullName)
12961282
.Execute()
12971283
.Should().Pass();

0 commit comments

Comments
 (0)