From ef749841b04132d4d2ac5a1f0575dca8d7758495 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 8 Jun 2026 23:37:18 -0700 Subject: [PATCH 1/2] Obsolete PublishAsConnectionString Mark the Hosting and Azure PublishAsConnectionString APIs obsolete because they only affect manifest publishing and do not update the publisher resource model. Update TypeScript codegen snapshots and suppress the intentional obsolete usages in existing coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ParameterEndToEnd.AppHost/AppHost.cs | 2 ++ .../AzureResourceExtensions.cs | 4 +++ .../ParameterResourceBuilderExtensions.cs | 4 +++ ...TwoPassScanningGeneratedAspire.verified.ts | 36 +++++++++++++++++++ .../PublishAsConnectionStringTests.cs | 5 ++- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs b/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs index b2e191eef1b..8c54df74981 100644 --- a/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs +++ b/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs @@ -15,9 +15,11 @@ // The expression below is a bit more complex than the average developer app would // probably have, but in our repo we'll probably want to experiment with seperately // deployed resources a little bit. +#pragma warning disable CS0618 // This playground intentionally exercises obsolete manifest-only PublishAsConnectionString behavior. var db = builder.AddSqlServer("sql") .PublishAsConnectionString() .AddDatabase("db"); +#pragma warning restore CS0618 var insertionrows = builder.AddParameter("insertionrows") .WithDescription("The number of rows to insert into the database."); diff --git a/src/Aspire.Hosting.Azure/AzureResourceExtensions.cs b/src/Aspire.Hosting.Azure/AzureResourceExtensions.cs index 3c7db938cb7..d5f2f422ef8 100644 --- a/src/Aspire.Hosting.Azure/AzureResourceExtensions.cs +++ b/src/Aspire.Hosting.Azure/AzureResourceExtensions.cs @@ -18,7 +18,11 @@ public static class AzureResourceExtensions /// The resource type. /// The resource builder. /// The configured . + /// + /// This API only changes the manifest representation; it does not change the resource model used by other publishers. + /// /// The resource builder. + [Obsolete("PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead.")] [AspireExport] public static IResourceBuilder PublishAsConnectionString(this IResourceBuilder builder) where T : IAzureResource, IResourceWithConnectionString diff --git a/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs b/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs index c121e583172..d0ffcf7de32 100644 --- a/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs +++ b/src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs @@ -363,7 +363,11 @@ internal static IResourceBuilder AddConnectionStr /// The resource type. /// The resource builder. /// The configured . + /// + /// This API only changes the manifest representation; it does not change the resource model used by other publishers. + /// /// The resource builder. + [Obsolete("PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead.")] [AspireExport] public static IResourceBuilder PublishAsConnectionString(this IResourceBuilder builder) where T : ContainerResource, IResourceWithConnectionString diff --git a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts index 8532ccdbd8c..bb75379ad07 100644 --- a/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts +++ b/tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts @@ -14067,7 +14067,10 @@ export interface ContainerResource { withOtlpExporter(options?: WithOtlpExporterOptions): ContainerResourcePromise; /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): ContainerResourcePromise; /** @@ -14808,7 +14811,10 @@ export interface ContainerResourcePromise extends PromiseLike withOtlpExporter(options?: WithOtlpExporterOptions): ContainerResourcePromise; /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): ContainerResourcePromise; /** @@ -15909,7 +15915,10 @@ class ContainerResourceImpl extends ResourceBuilderBase /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): ContainerResourcePromise { return new ContainerResourcePromiseImpl(this._publishAsConnectionStringInternal(), this._client); @@ -37423,7 +37432,10 @@ export interface TestDatabaseResource { withOtlpExporter(options?: WithOtlpExporterOptions): TestDatabaseResourcePromise; /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): TestDatabaseResourcePromise; /** @@ -38164,7 +38176,10 @@ export interface TestDatabaseResourcePromise extends PromiseLike withOtlpExporter(options?: WithOtlpExporterOptions): TestRedisResourcePromise; /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): TestRedisResourcePromise; /** @@ -43893,7 +43917,10 @@ class TestRedisResourceImpl extends ResourceBuilderBase /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): TestRedisResourcePromise { return new TestRedisResourcePromiseImpl(this._publishAsConnectionStringInternal(), this._client); @@ -46860,7 +46887,10 @@ export interface TestVaultResource { withOtlpExporter(options?: WithOtlpExporterOptions): TestVaultResourcePromise; /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): TestVaultResourcePromise; /** @@ -47603,7 +47633,10 @@ export interface TestVaultResourcePromise extends PromiseLike withOtlpExporter(options?: WithOtlpExporterOptions): TestVaultResourcePromise; /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): TestVaultResourcePromise; /** @@ -48705,7 +48738,10 @@ class TestVaultResourceImpl extends ResourceBuilderBase /** * Changes the resource to be published as a connection string reference in the manifest. + * + * This API only changes the manifest representation; it does not change the resource model used by other publishers. * @returns The resource builder. + * @deprecated PublishAsConnectionString only works with the manifest publisher and is obsolete. Use AddConnectionString in publish-mode app model code instead. */ publishAsConnectionString(): TestVaultResourcePromise { return new TestVaultResourcePromiseImpl(this._publishAsConnectionStringInternal(), this._client); diff --git a/tests/Aspire.Hosting.Tests/PublishAsConnectionStringTests.cs b/tests/Aspire.Hosting.Tests/PublishAsConnectionStringTests.cs index 68dc2fe1c99..6b2d05764a2 100644 --- a/tests/Aspire.Hosting.Tests/PublishAsConnectionStringTests.cs +++ b/tests/Aspire.Hosting.Tests/PublishAsConnectionStringTests.cs @@ -14,7 +14,10 @@ public async Task PublishAsConnectionStringConfiguresManifestAsParameter() { var builder = DistributedApplication.CreateBuilder(); - var redis = builder.AddRedis("redis").PublishAsConnectionString(); +#pragma warning disable CS0618 // Test intentionally covers obsolete PublishAsConnectionString manifest behavior. + var redis = builder.AddRedis("redis") + .PublishAsConnectionString(); +#pragma warning restore CS0618 Assert.True(redis.Resource.TryGetLastAnnotation(out _)); From eb405f44f15b3217b97ba20feb0c87a9550c2ea3 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Mon, 8 Jun 2026 23:53:55 -0700 Subject: [PATCH 2/2] Scope obsolete API suppression Limit the CS0618 suppression in the ParameterEndToEnd AppHost so it only covers the intentional PublishAsConnectionString call instead of the surrounding fluent chain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs b/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs index 8c54df74981..0773be7a1cd 100644 --- a/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs +++ b/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/AppHost.cs @@ -15,11 +15,11 @@ // The expression below is a bit more complex than the average developer app would // probably have, but in our repo we'll probably want to experiment with seperately // deployed resources a little bit. +var sql = builder.AddSqlServer("sql"); #pragma warning disable CS0618 // This playground intentionally exercises obsolete manifest-only PublishAsConnectionString behavior. -var db = builder.AddSqlServer("sql") - .PublishAsConnectionString() - .AddDatabase("db"); +sql.PublishAsConnectionString(); #pragma warning restore CS0618 +var db = sql.AddDatabase("db"); var insertionrows = builder.AddParameter("insertionrows") .WithDescription("The number of rows to insert into the database.");