Skip to content

Commit 4d6c3c6

Browse files
author
Mirroring
committed
Merge commit '5f32ae2439db56b36548861c02e17b6af8d54785'
2 parents eb020b5 + 5f32ae2 commit 4d6c3c6

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
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: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,10 @@ public async Task EndToEnd_MultiProjectSolution()
391391
.Execute()
392392
.Should().Pass();
393393

394-
// Add 'EnableSdkContainerSupport' property to the ConsoleApp and set TFM
394+
// set TFM for the console app
395395
using (FileStream stream = File.Open(Path.Join(newSolutionDir.FullName, "ConsoleApp", "ConsoleApp.csproj"), FileMode.Open, FileAccess.ReadWrite))
396396
{
397397
XDocument document = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None);
398-
document
399-
.Descendants()
400-
.First(e => e.Name.LocalName == "PropertyGroup")?
401-
.Add(new XElement("EnableSdkContainerSupport", "true"));
402398
document
403399
.Descendants()
404400
.First(e => e.Name.LocalName == "TargetFramework")
@@ -512,6 +508,8 @@ public async Task EndToEnd_MultiProjectSolution_with_multitargeted_library()
512508
[InlineData("webapi", true)]
513509
[InlineData("worker", false)]
514510
[InlineData("worker", true)]
511+
[InlineData("console", true)]
512+
[InlineData("console", false)]
515513
public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackageReference)
516514
{
517515
DirectoryInfo newProjectDir = new(Path.Combine(TestSettings.TestArtifactsDirectory, $"CreateNewImageTest_{projectType}_{addPackageReference}"));
@@ -564,7 +562,6 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
564562
var project = XDocument.Load(projectPath);
565563
var ns = project.Root?.Name.Namespace ?? throw new InvalidOperationException("Project file is empty");
566564

567-
project.Root?.Add(new XElement("PropertyGroup", new XElement("EnableSDKContainerSupport", "true")));
568565
project.Save(projectPath);
569566
}
570567

@@ -575,7 +572,7 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
575572
CommandResult commandResult = new DotnetCommand(
576573
_testOutput,
577574
"publish",
578-
"/p:PublishProfile=DefaultContainer",
575+
"/t:PublishContainer",
579576
"/p:RuntimeIdentifier=linux-x64",
580577
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
581578
$"/p:ContainerRegistry={DockerRegistryManager.LocalRegistry}",
@@ -604,21 +601,21 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
604601
var containerName = $"test-container-1-{projectType}-{addPackageReference}";
605602
CommandResult processResult = ContainerCli.RunCommand(
606603
_testOutput,
607-
"--rm",
608-
"--name",
609-
containerName,
610-
"-P",
611-
"--detach",
612-
$"{DockerRegistryManager.LocalRegistry}/{imageName}:{imageTag}")
604+
[
605+
"--rm",
606+
"--name",
607+
containerName,
608+
"-P",
609+
..projectType != "console" ? ["--detach"] : new string[]{},
610+
$"{DockerRegistryManager.LocalRegistry}/{imageName}:{imageTag}"
611+
])
613612
.Execute();
614613
processResult.Should().Pass();
615614
Assert.NotNull(processResult.StdOut);
616615
string appContainerId = processResult.StdOut.Trim();
617616

618617
bool everSucceeded = false;
619618

620-
621-
622619
if (projectType == "webapi")
623620
{
624621
var portCommand =
@@ -657,14 +654,13 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
657654
Assert.True(everSucceeded, $"{appUri}weatherforecast never responded.");
658655

659656
ContainerCli.StopCommand(_testOutput, appContainerId)
660-
.Execute()
661-
.Should().Pass();
657+
.Execute()
658+
.Should().Pass();
662659
}
663660
else if (projectType == "worker")
664661
{
665662
// the worker template needs a second to start up and emit the logs we are looking for
666663
await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);
667-
var containerLogs =
668664
ContainerCli.LogsCommand(_testOutput, appContainerId)
669665
.Execute()
670666
.Should().Pass()
@@ -673,10 +669,11 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
673669
ContainerCli.StopCommand(_testOutput, appContainerId)
674670
.Execute()
675671
.Should().Pass();
672+
676673
}
677-
else
674+
else if (projectType == "console")
678675
{
679-
throw new NotImplementedException("Unknown project type");
676+
processResult.Should().Pass().And.HaveStdOutContaining("Hello, World!");
680677
}
681678

682679
newProjectDir.Delete(true);
@@ -741,8 +738,7 @@ public void EndToEnd_NoAPI_Console(string baseImage)
741738
$"/p:ContainerBaseImage={baseImage}",
742739
$"/p:ContainerRegistry={DockerRegistryManager.LocalRegistry}",
743740
$"/p:ContainerRepository={imageName}",
744-
$"/p:ContainerImageTag={imageTag}",
745-
"/p:EnableSdkContainerSupport=true")
741+
$"/p:ContainerImageTag={imageTag}")
746742
.WithEnvironmentVariable("NUGET_PACKAGES", privateNuGetAssets.FullName)
747743
.WithWorkingDirectory(newProjectDir.FullName)
748744
.Execute()
@@ -782,8 +778,7 @@ public void EndToEnd_SingleArch_NoRid()
782778
"/t:PublishContainer",
783779
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
784780
$"/p:ContainerRepository={imageName}",
785-
$"/p:ContainerImageTag={imageTag}",
786-
"/p:EnableSdkContainerSupport=true")
781+
$"/p:ContainerImageTag={imageTag}")
787782
.WithWorkingDirectory(newProjectDir.FullName)
788783
.Execute();
789784
commandResult.Should().Pass();
@@ -818,8 +813,7 @@ public void EndToEndMultiArch_LocalRegistry(string imageName)
818813
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
819814
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
820815
$"/p:ContainerRepository={imageName}",
821-
$"/p:ContainerImageTag={tag}",
822-
"/p:EnableSdkContainerSupport=true")
816+
$"/p:ContainerImageTag={tag}")
823817
.WithWorkingDirectory(newProjectDir.FullName)
824818
.Execute();
825819

@@ -882,7 +876,6 @@ public void MultiArchStillAllowsSingleRID()
882876
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
883877
$"/p:ContainerRepository={imageName}",
884878
$"/p:ContainerImageTag={imageTag}",
885-
"/p:EnableSdkContainerSupport=true",
886879
"/bl")
887880
.WithWorkingDirectory(newProjectDir.FullName)
888881
.Execute();
@@ -932,7 +925,6 @@ public void MultiArchStillAllowsSingleRIDUsingJustRIDProperties()
932925
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
933926
$"/p:ContainerRepository={imageName}",
934927
$"/p:ContainerImageTag={imageTag}",
935-
"/p:EnableSdkContainerSupport=true",
936928
"/bl")
937929
.WithWorkingDirectory(newProjectDir.FullName)
938930
.Execute();
@@ -1005,8 +997,7 @@ public void EndToEndMultiArch_ArchivePublishing(string imageName)
1005997
$"/p:ContainerArchiveOutputPath={archiveOutput}",
1006998
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
1007999
$"/p:ContainerRepository={imageName}",
1008-
$"/p:ContainerImageTag={tag}",
1009-
"/p:EnableSdkContainerSupport=true")
1000+
$"/p:ContainerImageTag={tag}")
10101001
.WithWorkingDirectory(newProjectDir.FullName)
10111002
.Execute();
10121003

@@ -1076,8 +1067,7 @@ public void EndToEndMultiArch_RemoteRegistry()
10761067
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
10771068
$"/p:ContainerRegistry={registry}",
10781069
$"/p:ContainerRepository={imageName}",
1079-
$"/p:ContainerImageTag={imageTag}",
1080-
"/p:EnableSdkContainerSupport=true")
1070+
$"/p:ContainerImageTag={imageTag}")
10811071
.WithWorkingDirectory(newProjectDir.FullName)
10821072
.Execute();
10831073

@@ -1150,8 +1140,7 @@ public void EndToEndMultiArch_ContainerRuntimeIdentifiersOverridesRuntimeIdentif
11501140
"/p:ContainerRuntimeIdentifiers=linux-arm64",
11511141
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
11521142
$"/p:ContainerRepository={imageName}",
1153-
$"/p:ContainerImageTag={imageTag}",
1154-
"/p:EnableSdkContainerSupport=true")
1143+
$"/p:ContainerImageTag={imageTag}")
11551144
.WithWorkingDirectory(newProjectDir.FullName)
11561145
.Execute();
11571146

@@ -1201,8 +1190,7 @@ public void EndToEndMultiArch_EnvVariables()
12011190
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
12021191
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
12031192
$"/p:ContainerRepository={imageName}",
1204-
$"/p:ContainerImageTag={tag}",
1205-
"/p:EnableSdkContainerSupport=true")
1193+
$"/p:ContainerImageTag={tag}")
12061194
.WithWorkingDirectory(newProjectDir.FullName)
12071195
.Execute()
12081196
.Should().Pass();
@@ -1266,8 +1254,7 @@ public void EndToEndMultiArch_Ports()
12661254
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
12671255
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
12681256
$"/p:ContainerRepository={imageName}",
1269-
$"/p:ContainerImageTag={tag}",
1270-
"/p:EnableSdkContainerSupport=true")
1257+
$"/p:ContainerImageTag={tag}")
12711258
.WithWorkingDirectory(newProjectDir.FullName)
12721259
.Execute()
12731260
.Should().Pass();
@@ -1353,8 +1340,7 @@ public void EndToEndMultiArch_Labels()
13531340
"/p:RuntimeIdentifiers=\"linux-x64;linux-arm64\"",
13541341
$"/p:ContainerBaseImage={DockerRegistryManager.FullyQualifiedBaseImageAspNet}",
13551342
$"/p:ContainerRepository={imageName}",
1356-
$"/p:ContainerImageTag={tag}",
1357-
"/p:EnableSdkContainerSupport=true")
1343+
$"/p:ContainerImageTag={tag}")
13581344
.WithWorkingDirectory(newProjectDir.FullName)
13591345
.Execute()
13601346
.Should().Pass();

0 commit comments

Comments
 (0)