Skip to content

Commit c3b5f55

Browse files
authored
Set RuntimeIdentifier when building dotnet containers (#12936)
* Set RuntimeIdentifier when building dotnet containers Set both RuntimeIdentifier/ContainerRuntimeIdentifier or RuntimeIdentifiers/ContainerRuntimeIdentifiers when building dotnet containers. This way the application is published correctly - for example for native AOT. * Apply suggestion from @eerhardt
1 parent 6b8213b commit c3b5f55

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

playground/TestShop/BasketService/BasketService.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
55
<UserSecretsId>f0611710-1eab-4ff6-a476-9610bb7a8416</UserSecretsId>
6-
<ContainerRegistry>localhost:5001</ContainerRegistry>
76
<ContainerRepository>basket-service</ContainerRepository>
87
<ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:8.0</ContainerBaseImage>
98
</PropertyGroup>

playground/TestShop/CatalogService/CatalogService.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
55
<UserSecretsId>16965dbf-c1f8-4682-b7d8-e250ac520544</UserSecretsId>
66
<LangVersion>preview</LangVersion>
7-
<ContainerRegistry>localhost:5001</ContainerRegistry>
87
<ContainerRepository>catalog-service</ContainerRepository>
98
<ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:8.0</ContainerBaseImage>
109
</PropertyGroup>

playground/TestShop/MyFrontend/MyFrontend.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(DefaultTargetFramework)</TargetFramework>
5-
<ContainerRegistry>localhost:5001</ContainerRegistry>
65
<ContainerRepository>my-frontend</ContainerRepository>
76
<ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:8.0</ContainerBaseImage>
87
<!-- Razor tooling sometimes raises this warning. Don't make it an error. -->

src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,22 @@ private async Task<bool> ExecuteDotnetPublishAsync(IResource resource, Container
273273

274274
if (options.TargetPlatform is not null)
275275
{
276-
// Use the appropriate MSBuild property based on the number of RIDs
276+
// Use the appropriate MSBuild properties based on the number of RIDs
277277
var runtimeIds = options.TargetPlatform.Value.ToMSBuildRuntimeIdentifierString();
278278
var ridArray = runtimeIds.Split(';');
279279

280280
if (ridArray.Length == 1)
281281
{
282-
// Single platform - use ContainerRuntimeIdentifier
282+
// Single platform - use RuntimeIdentifier/ContainerRuntimeIdentifier
283+
arguments += $" /p:RuntimeIdentifier=\"{ridArray[0]}\"";
283284
arguments += $" /p:ContainerRuntimeIdentifier=\"{ridArray[0]}\"";
284285
}
285286
else
286287
{
287-
// Multiple platforms - use RuntimeIdentifiers
288-
arguments += $" /p:RuntimeIdentifiers=\"{runtimeIds}\"";
288+
// Multiple platforms - use RuntimeIdentifiers/ContainerRuntimeIdentifiers
289+
// MSBuild doesn't handle ';' in parameters well, need to escape the double quote. See https://github.com/dotnet/msbuild/issues/471
290+
arguments += $" /p:RuntimeIdentifiers=\\\"{runtimeIds}\\\"";
291+
arguments += $" /p:ContainerRuntimeIdentifiers=\\\"{runtimeIds}\\\"";
289292
}
290293
}
291294
}

0 commit comments

Comments
 (0)