|
41 | 41 | <ContainerRuntimeIdentifier Condition="'$(ContainerRuntimeIdentifier)' == '' and '$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier)</ContainerRuntimeIdentifier>
|
42 | 42 | <ContainerRuntimeIdentifiers Condition="'$(BuildingInsideVisualStudio)' != 'true' and '$(ContainerRuntimeIdentifiers)' == '' and '$(IsRidAgnostic)' != 'true'">$(RuntimeIdentifiers)</ContainerRuntimeIdentifiers>
|
43 | 43 | <ContainerRuntimeIdentifier Condition="'$(ContainerRuntimeIdentifier)' == '' and '$(ContainerRuntimeIdentifiers)' == ''">linux-$(NETCoreSdkPortableRuntimeIdentifier.Split('-')[1])</ContainerRuntimeIdentifier>
|
| 44 | + <!-- We want to save customer provided ContainerBaseImage to later set ContainerUser. --> |
| 45 | + <_InitialContainerBaseImage>$(ContainerBaseImage)</_InitialContainerBaseImage> |
44 | 46 | </PropertyGroup>
|
45 | 47 |
|
46 | 48 | <ItemGroup>
|
|
67 | 69 | </ItemGroup>
|
68 | 70 | </Target>
|
69 | 71 |
|
70 |
| - <Target Name="ComputeContainerConfig" DependsOnTargets="ComputeContainerBaseImage"> |
| 72 | + <!-- This Target is called early on in the chain for both single-RID and multi-RID containers - but for single-RID it's important |
| 73 | + that we ensure all of the data necessary to create a single-RID container is computed after we exit this target. --> |
| 74 | + <Target Name="ComputeContainerConfig" DependsOnTargets="ComputeContainerBaseImage;_ComputeContainerExecutionArgs"> |
71 | 75 | <PropertyGroup Label="VS defaults">
|
72 | 76 | <!-- RegistryUrl is used by existing VS targets for Docker builds - this lets us fill that void -->
|
73 | 77 | <ContainerRegistry Condition="'$(RegistryUrl)' != ''">$(RegistryUrl)</ContainerRegistry>
|
|
177 | 181 | <PropertyGroup>
|
178 | 182 | <PublishContainerDependsOn>
|
179 | 183 | _ContainerVerifySDKVersion;
|
| 184 | + _ContainerEstablishRIDNess; |
180 | 185 | ComputeContainerConfig;
|
181 | 186 | _CheckContainersPackage
|
182 | 187 | </PublishContainerDependsOn>
|
183 | 188 | </PropertyGroup>
|
184 | 189 |
|
185 | 190 | <!-- These args are relevant to container execution and are per-RID by nature. Therefore they're a direct dependency of the _PublishSingleContainer
|
186 |
| - target and not computed at the outer layer. --> |
187 |
| - <Target Name="_ComputeContainerExecutionArgs"> |
| 191 | + target and not computed at the outer, multi-RID build layer. --> |
| 192 | + <Target Name="_ComputeContainerExecutionArgs" Condition="'$(_IsSingleRIDBuild)' == 'true'"> |
188 | 193 | <PropertyGroup>
|
189 | 194 | <!-- The Container RID should default to the RID used for the entire build (to ensure things run on the platform they are built for), but the user knows best and so should be able to set it explicitly.
|
190 | 195 | For builds that have a RID, we default to that RID. Otherwise, we default to the Linux RID matching the architecture of the currently-executing SDK. -->
|
191 | 196 | <_ContainerIsTargetingWindows>false</_ContainerIsTargetingWindows>
|
192 | 197 | <_ContainerIsTargetingWindows Condition="$(ContainerRuntimeIdentifier.StartsWith('win'))">true</_ContainerIsTargetingWindows>
|
193 |
| - |
| 198 | + |
194 | 199 | <!-- Set the WorkingDirectory depending on the RID -->
|
195 | 200 | <ContainerWorkingDirectory Condition="'$(ContainerWorkingDirectory)' == '' and !$(_ContainerIsTargetingWindows)">/app/</ContainerWorkingDirectory>
|
196 | 201 | <ContainerWorkingDirectory Condition="'$(ContainerWorkingDirectory)' == '' and $(_ContainerIsTargetingWindows)">C:\app\</ContainerWorkingDirectory>
|
197 |
| - |
198 |
| - <_ContainerIsUsingMicrosoftDefaultImages Condition="'$(ContainerBaseImage)' == ''">true</_ContainerIsUsingMicrosoftDefaultImages> |
199 |
| - <_ContainerIsUsingMicrosoftDefaultImages Condition="'$(ContainerBaseImage)' != ''">false</_ContainerIsUsingMicrosoftDefaultImages> |
| 202 | + |
| 203 | + <_ContainerIsUsingMicrosoftDefaultImages Condition="'$(_InitialContainerBaseImage)' == ''">true</_ContainerIsUsingMicrosoftDefaultImages> |
| 204 | + <_ContainerIsUsingMicrosoftDefaultImages Condition="'$(_InitialContainerBaseImage)' != ''">false</_ContainerIsUsingMicrosoftDefaultImages> |
200 | 205 | </PropertyGroup>
|
201 | 206 |
|
202 | 207 | <!-- We only set a default user when the base image is Microsoft-authored, and we're targeting a version of those images that supports a nonroot user -->
|
|
245 | 250 | 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." />
|
246 | 251 | </Target>
|
247 | 252 |
|
248 |
| - <Target Name="_PublishSingleContainer" DependsOnTargets="_ComputeContainerExecutionArgs" Returns="@(GeneratedContainer)"> |
| 253 | + <!-- There is an implicit dependency here in that both of ComputeContainerConfig and _ComputeContainerExecutionArgs must have been run, but because we call this Target |
| 254 | + in a few different ways we can't express that dependency directly here. --> |
| 255 | + <Target Name="_PublishSingleContainer" Returns="@(GeneratedContainer)"> |
249 | 256 | <PropertyGroup Condition="'$(DOTNET_HOST_PATH)' == ''">
|
250 | 257 | <DotNetHostDirectory>$(NetCoreRoot)</DotNetHostDirectory>
|
251 | 258 | <DotNetHostFileName>dotnet</DotNetHostFileName>
|
|
342 | 349 | ContainerGenerateLabels=$(ContainerGenerateLabels);
|
343 | 350 | ContainerGenerateLabelsImageBaseDigest=$(ContainerGenerateLabelsImageBaseDigest);
|
344 | 351 | _SkipContainerPublishing=$(_SkipContainerPublishing);
|
345 |
| - ContainerImageFormat=$(_SingleImageContainerFormat) |
| 352 | + ContainerImageFormat=$(_SingleImageContainerFormat); |
| 353 | + _IsMultiRIDBuild=false; |
| 354 | + _IsSingleRIDBuild=true; |
| 355 | + _InitialContainerBaseImage=$(_InitialContainerBaseImage) |
346 | 356 | "/>
|
347 | 357 | <_rids Remove ="$(_rids)" />
|
348 | 358 | </ItemGroup>
|
349 | 359 |
|
350 | 360 | <MSBuild
|
351 | 361 | Projects="@(_InnerBuild)"
|
352 |
| - Targets="Publish;_ParseItemsForPublishingSingleContainer;_PublishSingleContainer" |
| 362 | + Targets="Publish;_ParseItemsForPublishingSingleContainer;_ComputeContainerExecutionArgs;_PublishSingleContainer" |
353 | 363 | BuildInParallel="$([MSBuild]::ValueOrDefault('$(ContainerPublishInParallel)', 'true'))">
|
354 | 364 | <Output TaskParameter="TargetOutputs" ItemName="GeneratedContainer" />
|
355 | 365 | </MSBuild>
|
|
401 | 411 | </ItemGroup>
|
402 | 412 | </Target>
|
403 | 413 |
|
404 |
| - <Target Name="PublishContainer" |
405 |
| - DependsOnTargets="$(PublishContainerDependsOn)" |
406 |
| - Condition="'$(IsPublishable)' == 'true' AND '$(EnableSdkContainerSupport)' == 'true'" |
407 |
| - Returns="@(GeneratedContainer)" |
408 |
| - > |
| 414 | + <Target Name="_ContainerEstablishRIDNess"> |
409 | 415 | <PropertyGroup>
|
410 | 416 | <_IsMultiTFMBuild Condition="'$(TargetFrameworks)' != '' and '$(TargetFramework)' == ''">true</_IsMultiTFMBuild>
|
411 | 417 | <!-- we are multi-RID if:
|
|
415 | 421 | <_HasCRIDsAndNoCRID Condition="'$(ContainerRuntimeIdentifiers)' != '' and '$(ContainerRuntimeIdentifier)' == ''">true</_HasCRIDsAndNoCRID>
|
416 | 422 | <_HasRIDs Condition="'$(RuntimeIdentifiers)' != ''">true</_HasRIDs>
|
417 | 423 | <_NoCRIDsOrCRIDorRID Condition="'$(ContainerRuntimeIdentifiers)' == '' and '$(ContainerRuntimeIdentifier)' == '' and '$(RuntimeIdentifier)' == ''">true</_NoCRIDsOrCRIDorRID>
|
| 424 | + <!-- these two are load-bearing for other comparisons - see _ComputeContainerExecutionArgs --> |
418 | 425 | <_IsMultiRIDBuild Condition="'$(BuildingInsideVisualStudio)' != 'true' and ('$(_HasCRIDsAndNoCRID)' == true or ('$(_HasRIDs)' == 'true' and '$(_NoCRIDsOrCRIDorRID)' == 'true'))">true</_IsMultiRIDBuild>
|
419 | 426 | <_IsSingleRIDBuild Condition="'$(_IsMultiRIDBuild)' == ''">true</_IsSingleRIDBuild>
|
420 | 427 | </PropertyGroup>
|
| 428 | + </Target> |
421 | 429 |
|
| 430 | + <Target Name="PublishContainer" |
| 431 | + DependsOnTargets="$(PublishContainerDependsOn)" |
| 432 | + Condition="'$(IsPublishable)' == 'true' AND '$(EnableSdkContainerSupport)' == 'true'" |
| 433 | + Returns="@(GeneratedContainer)" |
| 434 | + > |
422 | 435 | <!-- Call _PublishMultiArchContainers if we are in a multi-rid build, and call _PublishSingleContainer if we are in a single-RID build -->
|
423 | 436 | <CallTarget Condition="'$(_IsMultiRIDBuild)' == 'true' " Targets="_PublishMultiArchContainers">
|
424 | 437 | <Output TaskParameter="TargetOutputs" ItemName="GeneratedContainer" />
|
|
0 commit comments