Skip to content

Commit d5cd19d

Browse files
author
Mirroring
committed
Merge commit 'cf4b8cacabc0d73e7695bd69169a94f1aea180ad'
2 parents a94faf9 + cf4b8ca commit d5cd19d

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,42 @@
188188
</PublishContainerDependsOn>
189189
</PropertyGroup>
190190

191-
<!-- TODO: change this comparison to include $(EnableSdkContainerSupport) == true when console apps Import the Publish SDK -->
191+
<Target Name="_CheckContainersPackage" AfterTargets="Build">
192+
<PropertyGroup>
193+
<!-- facts to base on comparisons on -->
194+
<_ContainersPackageIdentity>Microsoft.NET.Build.Containers</_ContainersPackageIdentity>
195+
<_WebDefaultSdkVersion>7.0.300</_WebDefaultSdkVersion>
196+
<_WorkerDefaultSdkVersion>8.0.100</_WorkerDefaultSdkVersion>
197+
<_ConsoleDefaultSdkVersion>8.0.200</_ConsoleDefaultSdkVersion>
198+
199+
<!-- capability detection for the executing SDK -->
200+
<_SdkCanPublishWeb>$([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreSdkVersion)', '$(_WebDefaultSdkVersion)'))</_SdkCanPublishWeb>
201+
<_SdkCanPublishWorker>$([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreSdkVersion)', '$(_WorkerDefaultSdkVersion)'))</_SdkCanPublishWorker>
202+
<_SdkCanPublishConsole>$([MSBuild]::VersionGreaterThanOrEquals('$(NETCoreSdkVersion)', '$(_ConsoleDefaultSdkVersion)'))</_SdkCanPublishConsole>
203+
204+
<!-- capability detection for the executing project -->
205+
<_ContainerPackageIsPresent>false</_ContainerPackageIsPresent>
206+
<_ContainerPackageIsPresent Condition="@(PackageReference->AnyHaveMetadataValue('Identity', '$(_ContainersPackageIdentity)'))">true</_ContainerPackageIsPresent>
207+
<_IsWebProject>false</_IsWebProject>
208+
<_IsWebProject Condition="@(ProjectCapability->AnyHaveMetadataValue('Identity', 'DotNetCoreWeb'))">true</_IsWebProject>
209+
<_IsWorkerProject>false</_IsWorkerProject>
210+
<_IsWorkerProject Condition="@(ProjectCapability->AnyHaveMetadataValue('Identity', 'DotNetCoreWorker'))">true</_IsWorkerProject>
211+
</PropertyGroup>
212+
213+
<Warning
214+
Condition="$(_ContainerPackageIsPresent)
215+
and (
216+
($(_SdkCanPublishWeb) and $(_IsWebProject)) or
217+
($(_SdkCanPublishWorker) and $(_IsWorkerProject)) or
218+
($(_SdkCanPublishConsole) and '$(EnableSdkContainerSupport)' == 'true')
219+
)"
220+
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." />
221+
222+
<PropertyGroup>
223+
<EnableSdkContainerSupport Condition="'@(ContainersPackage)' != ''">true</EnableSdkContainerSupport>
224+
</PropertyGroup>
225+
</Target>
226+
192227
<Target Name="PublishContainer"
193228
DependsOnTargets="$(PublishContainerDependsOn)"
194229
Condition="'$(IsPublishable)' == 'true'">

src/Tests/Microsoft.NET.Build.Containers.IntegrationTests/EndToEndTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public async Task EndToEnd_NoAPI_ProjectType(string projectType, bool addPackage
293293

294294
if (addPackageReference)
295295
{
296-
commandResult.Should().HaveStdOutContaining("warning : Microsoft.NET.Build.Containers NuGet package is explicitly referenced. Consider removing the package reference to Microsoft.NET.Build.Containers as it is now part of .NET SDK.");
296+
commandResult.Should().HaveStdOutContaining("warning : The Microsoft.NET.Build.Containers NuGet package is explicitly referenced but the current SDK can natively publish the project as a container. Consider removing the package reference to Microsoft.NET.Build.Containers because it is no longer needed.");
297297
}
298298
else
299299
{
@@ -443,7 +443,8 @@ public void EndToEnd_NoAPI_Console()
443443
$"/p:ContainerRegistry={DockerRegistryManager.LocalRegistry}",
444444
$"/p:ContainerRepository={imageName}",
445445
$"/p:RuntimeFrameworkVersion=8.0.0-preview.3.23174.8",
446-
$"/p:ContainerImageTag={imageTag}")
446+
$"/p:ContainerImageTag={imageTag}",
447+
"/p:EnableSdkContainerSupport=true")
447448
.WithEnvironmentVariable("NUGET_PACKAGES", privateNuGetAssets.FullName)
448449
.WithWorkingDirectory(newProjectDir.FullName)
449450
.Execute()

0 commit comments

Comments
 (0)