From 805095aaa67717956c0160cc0cf0f309cbecc4f1 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Wed, 11 Dec 2024 11:59:25 +0100 Subject: [PATCH 01/13] WIP Signed-off-by: Jonathan Mezach --- Directory.Packages.props | 1 + ...Hosting.SqlDatabaseProjects.AppHost.csproj | 3 + .../MoveToPackage.targets | 65 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets diff --git a/Directory.Packages.props b/Directory.Packages.props index cb428411..6dd27f64 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -53,6 +53,7 @@ + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj index 87d2ed3a..6a08d6e3 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj @@ -12,6 +12,7 @@ + @@ -19,4 +20,6 @@ + + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets new file mode 100644 index 00000000..6d850cf8 --- /dev/null +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets @@ -0,0 +1,65 @@ + + + + + <_AspirePackageResource Include="@(PackageReference->WithMetadataValue('IsAspirePackageResource', 'true'))" /> + + + + + + + + + $([System.Text.RegularExpressions.Regex]::Replace($([System.IO.Path]::GetFileNameWithoutExtension(%(_AspirePackageResource.Identity))), $(_GeneratedClassNameFixupRegex), '_')) + $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.AspirePackageMetadataTypeName), $(_GeneratedClassNameFixupRegex), '_')) + @(_AspirePackageResource->'%(Identity)'->Replace('.', '_')) + $(Pkg%(_AspirePackageResource.PackageName)) + %(PackageVersion.PackageVersion) + $([System.String]::new('$(NuGetPackageRoot)%(_AspirePackageResource.Identity)/%(_AspirePackageResource.PackageVersion)').ToLower()) + + + + + + + + + + +namespace Packages%3B + +[global::System.CodeDom.Compiler.GeneratedCode("Aspire.Hosting", null)] +[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage(Justification = "Generated code.")] +[global::System.Diagnostics.DebuggerDisplay("Type = {GetType().Name,nq}, ProjectPath = {ProjectPath}")] +]]>$(AspireGeneratedClassesVisibility)%(ClassName) """]]>%(Identity) """]]>%(PackagePath) + + + + + + + + + + + + + + _CSharpWritePackageMetadataSources; + + + + + \ No newline at end of file From c3dd6638cefe3b40f1e88517aa0596e84cd6cb63 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Wed, 11 Dec 2024 14:03:46 +0100 Subject: [PATCH 02/13] Put metadata on PackageVersion element for CPM Signed-off-by: Jonathan Mezach --- Directory.Packages.props | 2 +- .../MoveToPackage.targets | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6dd27f64..2a965061 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -53,7 +53,7 @@ - + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets index 6d850cf8..c2d021c8 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets @@ -2,7 +2,8 @@ - <_AspirePackageResource Include="@(PackageReference->WithMetadataValue('IsAspirePackageResource', 'true'))" /> + <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'!='true'" Include="@(PackageReference->WithMetadataValue('IsAspirePackageResource', 'true'))" /> + <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'=='true'" Include="@(PackageVersion->WithMetadataValue('IsAspirePackageResource', 'true'))" /> @@ -16,8 +17,7 @@ $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.AspirePackageMetadataTypeName), $(_GeneratedClassNameFixupRegex), '_')) @(_AspirePackageResource->'%(Identity)'->Replace('.', '_')) $(Pkg%(_AspirePackageResource.PackageName)) - %(PackageVersion.PackageVersion) - $([System.String]::new('$(NuGetPackageRoot)%(_AspirePackageResource.Identity)/%(_AspirePackageResource.PackageVersion)').ToLower()) + $([System.String]::new('$(NuGetPackageRoot)%(_AspirePackageResource.Identity)/%(_AspirePackageResource.Version)').ToLower()) From 82c0a62d1c5f53abbd68c63ff90f441c6a80f24a Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Thu, 12 Dec 2024 16:53:04 +0100 Subject: [PATCH 03/13] Allow specifying a relative path within package Signed-off-by: Jonathan Mezach --- .../Program.cs | 3 +++ .../IPackageMetadata.cs | 18 ++++++++++++++++++ .../SqlProjectBuilderExtensions.cs | 19 +++++++++++++++++++ .../SqlProjectResource.cs | 13 +++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs index aa380a71..d84e9826 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs @@ -6,4 +6,7 @@ builder.AddSqlProject("sdk-project") .WithReference(server); +builder.AddSqlPackage("dacpac-project", "tools/master.dacpac") + .WithReference(server); + builder.Build().Run(); diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs new file mode 100644 index 00000000..44facc41 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs @@ -0,0 +1,18 @@ +using Aspire.Hosting.ApplicationModel; + +namespace Aspire.Hosting; + +/// +/// +/// +public interface IPackageMetadata : IResourceAnnotation +{ + /// + /// + /// + string PackageId { get; } + /// + /// + /// + string PackagePath { get; } +} \ No newline at end of file diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs index 4ea2b74d..1e8d9ae9 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs @@ -40,6 +40,25 @@ public static IResourceBuilder AddSqlProject(this .WithAnnotation(new TProject()); } + /// + /// + /// + /// + /// + /// + /// + /// + public static IResourceBuilder AddSqlPackage(this IDistributedApplicationBuilder builder, [ResourceName]string name, string relativePathToDacpac) + where TPackage : IPackageMetadata, new() + { + ArgumentNullException.ThrowIfNull(builder, nameof(builder)); + ArgumentNullException.ThrowIfNull(name, nameof(name)); + + return builder.AddSqlProject(name) + .WithAnnotation(new TPackage()) + .WithAnnotation(new DacpacMetadataAnnotation(relativePathToDacpac)); + } + /// /// Adds a SQL Server Database Project resource to the application. /// diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs index 68391fde..e7268170 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs @@ -27,6 +27,19 @@ internal string GetDacpacPath() return targetPath; } + if (this.TryGetLastAnnotation(out var packageMetadata)) + { + var packagePath = packageMetadata.PackagePath; + if (this.TryGetLastAnnotation(out var relativeDacpacMetadata)) + { + return Path.Combine(packagePath, relativeDacpacMetadata.DacpacPath); + } + else + { + return Path.Combine(packagePath, "tools", packageMetadata.PackageId + ".dacpac"); + } + } + if (this.TryGetLastAnnotation(out var dacpacMetadata)) { return dacpacMetadata.DacpacPath; From 61828e0f84ea149eaa0b237dd8319c4205f9ebab Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Thu, 12 Dec 2024 17:05:01 +0100 Subject: [PATCH 04/13] Generate package version into package metadata Signed-off-by: Jonathan Mezach --- .../MoveToPackage.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets index c2d021c8..fceb4ca0 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets @@ -37,6 +37,7 @@ namespace Packages%3B { public string PackageId => """]]>%(Identity) """]]>%(PackagePath) new Version("""]]>%(Version) From 976d3f6eb974236cdbb718b64ffd3c61b95b0924 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Mon, 16 Dec 2024 14:51:02 +0100 Subject: [PATCH 05/13] Refactor to simplify Move targets file into package Signed-off-by: Jonathan Mezach --- ...Hosting.SqlDatabaseProjects.AppHost.csproj | 2 +- .../Program.cs | 3 +- .../IPackageMetadata.cs | 12 ++++-- .../PublicAPI.Unshipped.txt | 5 +++ .../SqlProjectBuilderExtensions.cs | 38 ++++++++----------- .../SqlProjectPublishService.cs | 10 ++++- .../SqlProjectResource.cs | 2 +- ...Aspire.Hosting.SqlDatabaseProjects.targets | 15 +++++--- ...Aspire.Hosting.SqlDatabaseProjects.targets | 3 ++ 9 files changed, 55 insertions(+), 35 deletions(-) rename examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets => src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets (85%) create mode 100644 src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/buildMultiTargeting/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj index 6a08d6e3..abc9119f 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj @@ -20,6 +20,6 @@ - + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs index d84e9826..f8437fb1 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs @@ -6,7 +6,8 @@ builder.AddSqlProject("sdk-project") .WithReference(server); -builder.AddSqlPackage("dacpac-project", "tools/master.dacpac") +builder.AddSqlPackage("dacpac-project") + .WithDacpac("tools/master.dacpac") .WithReference(server); builder.Build().Run(); diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs index 44facc41..4b431b5d 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/IPackageMetadata.cs @@ -3,16 +3,22 @@ namespace Aspire.Hosting; /// -/// +/// Represents metadata for a referenced NuGet package. /// public interface IPackageMetadata : IResourceAnnotation { /// - /// + /// Gets the unique identifier of the package. /// string PackageId { get; } + + /// + /// Gets the version of the package. + /// + Version PackageVersion { get; } + /// - /// + /// Gets the physical location on disk of the package. /// string PackagePath { get; } } \ No newline at end of file diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/PublicAPI.Unshipped.txt b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/PublicAPI.Unshipped.txt index d5d6b090..f8150459 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/PublicAPI.Unshipped.txt +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/PublicAPI.Unshipped.txt @@ -4,3 +4,8 @@ Aspire.Hosting.ApplicationModel.ConfigureDacDeployOptionsAnnotation.ConfigureDac Aspire.Hosting.ApplicationModel.ConfigureDacDeployOptionsAnnotation.ConfigureDeploymentOptions.get -> System.Action! Aspire.Hosting.ApplicationModel.ConfigureDacDeployOptionsAnnotation.ConfigureDeploymentOptions.init -> void static Aspire.Hosting.SqlProjectBuilderExtensions.WithConfigureDacDeployOptions(this Aspire.Hosting.ApplicationModel.IResourceBuilder! builder, System.Action! configureDeploymentOptions) -> Aspire.Hosting.ApplicationModel.IResourceBuilder! +Aspire.Hosting.IPackageMetadata +Aspire.Hosting.IPackageMetadata.PackageId.get -> string! +Aspire.Hosting.IPackageMetadata.PackageVersion.get -> System.Version! +Aspire.Hosting.IPackageMetadata.PackagePath.get -> string! +static Aspire.Hosting.SqlProjectBuilderExtensions.AddSqlPackage(this Aspire.Hosting.IDistributedApplicationBuilder! builder, string! name) -> Aspire.Hosting.ApplicationModel.IResourceBuilder! diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs index 1e8d9ae9..89828749 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs @@ -41,38 +41,37 @@ public static IResourceBuilder AddSqlProject(this } /// - /// + /// Adds a SQL Server Database Project resource to the application. /// - /// - /// - /// - /// - /// - public static IResourceBuilder AddSqlPackage(this IDistributedApplicationBuilder builder, [ResourceName]string name, string relativePathToDacpac) - where TPackage : IPackageMetadata, new() + /// An instance to add the SQL Server Database project to. + /// Name of the resource. + /// An that can be used to further customize the resource. + public static IResourceBuilder AddSqlProject(this IDistributedApplicationBuilder builder, [ResourceName]string name) { ArgumentNullException.ThrowIfNull(builder, nameof(builder)); ArgumentNullException.ThrowIfNull(name, nameof(name)); - return builder.AddSqlProject(name) - .WithAnnotation(new TPackage()) - .WithAnnotation(new DacpacMetadataAnnotation(relativePathToDacpac)); + var resource = new SqlProjectResource(name); + + return builder.AddResource(resource) + .ExcludeFromManifest(); } /// - /// Adds a SQL Server Database Project resource to the application. + /// Adds a SQL Server Database Project resource to the application based on a referenced NuGet package. /// + /// Type that represents the NuGet package that contains the .dacpac file. /// An instance to add the SQL Server Database project to. /// Name of the resource. - /// An that can be used to further customize the resource. - public static IResourceBuilder AddSqlProject(this IDistributedApplicationBuilder builder, [ResourceName]string name) + /// Am that can be used to further customize the resource. + public static IResourceBuilder AddSqlPackage(this IDistributedApplicationBuilder builder, [ResourceName]string name) + where TPackage : IPackageMetadata, new() { ArgumentNullException.ThrowIfNull(builder, nameof(builder)); ArgumentNullException.ThrowIfNull(name, nameof(name)); - var resource = new SqlProjectResource(name); - - return builder.AddResource(resource) + return builder.AddSqlProject(name) + .WithAnnotation(new TPackage()) .ExcludeFromManifest(); } @@ -84,11 +83,6 @@ public static IResourceBuilder AddSqlProject(this IDistribut /// An that can be used to further customize the resource. public static IResourceBuilder WithDacpac(this IResourceBuilder builder, string dacpacPath) { - if (!Path.IsPathRooted(dacpacPath)) - { - dacpacPath = Path.Combine(builder.ApplicationBuilder.AppHostDirectory, dacpacPath); - } - return builder.WithAnnotation(new DacpacMetadataAnnotation(dacpacPath)); } diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectPublishService.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectPublishService.cs index 3d37d0c8..9f28bec7 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectPublishService.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectPublishService.cs @@ -1,10 +1,13 @@ +using Aspire.Hosting; using Aspire.Hosting.ApplicationModel; using Aspire.Hosting.Eventing; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects; -internal class SqlProjectPublishService(IDacpacDeployer deployer, ResourceLoggerService resourceLoggerService, ResourceNotificationService resourceNotificationService, IDistributedApplicationEventing eventing, IServiceProvider serviceProvider) +internal class SqlProjectPublishService(IDacpacDeployer deployer, IHostEnvironment hostEnvironment, ResourceLoggerService resourceLoggerService, ResourceNotificationService resourceNotificationService, IDistributedApplicationEventing eventing, IServiceProvider serviceProvider) { public async Task PublishSqlProject(SqlProjectResource sqlProject, SqlServerDatabaseResource target, CancellationToken cancellationToken) { @@ -13,6 +16,11 @@ public async Task PublishSqlProject(SqlProjectResource sqlProject, SqlServerData try { var dacpacPath = sqlProject.GetDacpacPath(); + if (!Path.IsPathRooted(dacpacPath)) + { + dacpacPath = Path.Combine(hostEnvironment.ContentRootPath, dacpacPath); + } + if (!File.Exists(dacpacPath)) { logger.LogError("SQL Server Database project package not found at path {DacpacPath}.", dacpacPath); diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs index e7268170..ad1bb4da 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectResource.cs @@ -32,7 +32,7 @@ internal string GetDacpacPath() var packagePath = packageMetadata.PackagePath; if (this.TryGetLastAnnotation(out var relativeDacpacMetadata)) { - return Path.Combine(packagePath, relativeDacpacMetadata.DacpacPath); + return Path.Combine(packagePath, relativeDacpacMetadata.DacpacPath);; } else { diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets similarity index 85% rename from examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets rename to src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets index fceb4ca0..66502977 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/MoveToPackage.targets +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets @@ -1,9 +1,13 @@ + + + + - <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'!='true'" Include="@(PackageReference->WithMetadataValue('IsAspirePackageResource', 'true'))" /> - <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'=='true'" Include="@(PackageVersion->WithMetadataValue('IsAspirePackageResource', 'true'))" /> + <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'!='true'" Include="@(PackageReference->WithMetadataValue('IsAspirePackageResource', 'true')" /> + <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'=='true'" Include="@(ResolvedPackageReferences->WithMetadataValue('IsAspirePackageResource', 'true'))" /> @@ -16,8 +20,7 @@ $([System.Text.RegularExpressions.Regex]::Replace($([System.IO.Path]::GetFileNameWithoutExtension(%(_AspirePackageResource.Identity))), $(_GeneratedClassNameFixupRegex), '_')) $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.AspirePackageMetadataTypeName), $(_GeneratedClassNameFixupRegex), '_')) @(_AspirePackageResource->'%(Identity)'->Replace('.', '_')) - $(Pkg%(_AspirePackageResource.PackageName)) - $([System.String]::new('$(NuGetPackageRoot)%(_AspirePackageResource.Identity)/%(_AspirePackageResource.Version)').ToLower()) + $([System.String]::new('$(NuGetPackageRoot)%(_AspirePackageResource.Identity)/%(_AspirePackageResource.Version)').ToLower()) @@ -32,12 +35,12 @@ namespace Packages%3B [global::System.CodeDom.Compiler.GeneratedCode("Aspire.Hosting", null)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage(Justification = "Generated code.")] -[global::System.Diagnostics.DebuggerDisplay("Type = {GetType().Name,nq}, ProjectPath = {ProjectPath}")] +[global::System.Diagnostics.DebuggerDisplay("Type = {GetType().Name,nq}, PackageId = {PackageId}, PackageVersion = {PackageVersion}, PackagePath = {PackagePath}")] ]]>$(AspireGeneratedClassesVisibility)%(ClassName) """]]>%(Identity) """]]>%(PackagePath) new Version("""]]>%(Version) """]]>%(PackagePath) diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/buildMultiTargeting/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/buildMultiTargeting/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets new file mode 100644 index 00000000..272417c6 --- /dev/null +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/buildMultiTargeting/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets @@ -0,0 +1,3 @@ + + + \ No newline at end of file From cb4da4ef09803c22b14ec616f3c80f423f58f899 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Mon, 16 Dec 2024 18:55:16 +0100 Subject: [PATCH 06/13] Fix resolving of IsAspirePackageResource Signed-off-by: Jonathan Mezach --- Directory.Packages.props | 2 +- ...Aspire.Hosting.SqlDatabaseProjects.targets | 22 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 2a965061..6dd27f64 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -53,7 +53,7 @@ - + diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets index 66502977..81793f2b 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets @@ -1,22 +1,18 @@ - - - - - - - <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'!='true'" Include="@(PackageReference->WithMetadataValue('IsAspirePackageResource', 'true')" /> - <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'=='true'" Include="@(ResolvedPackageReferences->WithMetadataValue('IsAspirePackageResource', 'true'))" /> - - - + + <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'!='true'" Include="@(PackageReference->WithMetadataValue('IsAspirePackageResource', 'true'))" /> + <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'=='true'" Include="@(PackageVersion)" /> + <_AspirePackageResource Condition="'$(ManagePackageVersionsCentrally)'=='true'" Update="@(PackageReference)"> + %(PackageReference.IsAspirePackageResource) + + + DependsOnTargets="_CreateAspireProjectResources"> - + $([System.Text.RegularExpressions.Regex]::Replace($([System.IO.Path]::GetFileNameWithoutExtension(%(_AspirePackageResource.Identity))), $(_GeneratedClassNameFixupRegex), '_')) $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.AspirePackageMetadataTypeName), $(_GeneratedClassNameFixupRegex), '_')) @(_AspirePackageResource->'%(Identity)'->Replace('.', '_')) From 132ca0e0ca90c912912f633dad60513582495a17 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 17 Dec 2024 07:46:11 +0100 Subject: [PATCH 07/13] Fix broken test Signed-off-by: Jonathan Mezach --- .../AddSqlProjectTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs index df7d0f56..9cfeddcb 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs @@ -41,7 +41,7 @@ public void AddSqlProject_WithExplicitPath() Assert.Equal("MySqlProject", sqlProjectResource.Name); Assert.True(sqlProjectResource.TryGetLastAnnotation(out DacpacMetadataAnnotation? dacpacMetadataAnnotation)); - Assert.Equal(Path.Combine(appBuilder.AppHostDirectory, TestProject.RelativePath), dacpacMetadataAnnotation.DacpacPath); + Assert.Equal(TestProject.RelativePath, dacpacMetadataAnnotation.DacpacPath); var dacpacPath = sqlProjectResource.GetDacpacPath(); Assert.NotNull(dacpacPath); From 7f43569335a39f5b1ac360f7ef86cdf8204bb64a Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 17 Dec 2024 08:02:16 +0100 Subject: [PATCH 08/13] Add initial tests for package based SQL Database Projects Signed-off-by: Jonathan Mezach --- .../AddSqlPackageTests.cs | 46 +++++++++++++++++++ .../AddSqlProjectTests.cs | 2 +- .../TestPackage.cs | 14 ++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs create mode 100644 tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs new file mode 100644 index 00000000..6fb0fbf5 --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs @@ -0,0 +1,46 @@ +using Aspire.Hosting; + +namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests; + +public class AddSqlPackageTests +{ + [Fact] + public void AddSqlPackage_WithPackageMetadata() + { + // Arrange + var appBuilder = DistributedApplication.CreateBuilder(); + appBuilder.AddSqlPackage("master"); + + // Act + using var app = appBuilder.Build(); + var appModel = app.Services.GetRequiredService(); + + // Assert + var sqlProjectResource = Assert.Single(appModel.Resources.OfType()); + Assert.Equal("master", sqlProjectResource.Name); + + var dacpacPath = sqlProjectResource.GetDacpacPath(); + Assert.NotNull(dacpacPath); + Assert.Equal(Path.Combine(TestPackage.PackageBasePath, "tools", "Microsoft.SqlServer.Dacpacs.Master.dacpac"), dacpacPath); + } + + [Fact] + public void AddSqlPackage_WithExplicitRelativePath() + { + // Arrange + var appBuilder = DistributedApplication.CreateBuilder(); + appBuilder.AddSqlPackage("master").WithDacpac("tools/master.dacpac"); + + // Act + using var app = appBuilder.Build(); + var appModel = app.Services.GetRequiredService(); + + // Assert + var sqlProjectResource = Assert.Single(appModel.Resources.OfType()); + Assert.Equal("master", sqlProjectResource.Name); + + var dacpacPath = sqlProjectResource.GetDacpacPath(); + Assert.NotNull(dacpacPath); + Assert.True(File.Exists(dacpacPath)); + } +} \ No newline at end of file diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs index 9cfeddcb..34989318 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlProjectTests.cs @@ -96,7 +96,7 @@ public void AddSqlProject_WithDeploymentOptions() } [Fact] - public void PublishTo_AddsRequiredServices() + public void WithReference_AddsRequiredServices() { // Arrange var appBuilder = DistributedApplication.CreateBuilder(); diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs new file mode 100644 index 00000000..638c60a7 --- /dev/null +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs @@ -0,0 +1,14 @@ +using Aspire.Hosting; + +namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests; + +internal class TestPackage : IPackageMetadata +{ + public static readonly string PackageBasePath = Path.Combine(Environment.GetEnvironmentVariable("HOME") ?? "", ".nuget", "packages", "microsoft.sqlserver.dacpacs.master", "160.2.3"); + + public string PackageId { get; } = "Microsoft.SqlServer.Dacpacs.Master"; + + public Version PackageVersion { get; } = new Version(160, 2, 3); + + public string PackagePath { get; } = PackageBasePath; +} \ No newline at end of file From 081df1807a7a73b72172ee0b8ba7ce580d5005a2 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 17 Dec 2024 08:04:01 +0100 Subject: [PATCH 09/13] Make sure we include MSBuild logic in packae Signed-off-by: Jonathan Mezach --- ...CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.csproj b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.csproj index c4d82c22..38a207cd 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.csproj +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.csproj @@ -14,6 +14,10 @@ + + + + From 09755e00be628220c2b16da34f0b2f79e5c8e3b4 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 17 Dec 2024 08:24:34 +0100 Subject: [PATCH 10/13] Attempt to make tests work on Windows Signed-off-by: Jonathan Mezach --- .../AddSqlPackageTests.cs | 2 +- .../TestPackage.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs index 6fb0fbf5..b4d0530c 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs @@ -21,7 +21,7 @@ public void AddSqlPackage_WithPackageMetadata() var dacpacPath = sqlProjectResource.GetDacpacPath(); Assert.NotNull(dacpacPath); - Assert.Equal(Path.Combine(TestPackage.PackageBasePath, "tools", "Microsoft.SqlServer.Dacpacs.Master.dacpac"), dacpacPath); + Assert.Equal(Path.Combine(TestPackage.NuGetPackageCache, "microsoft.sqlserver.dacpacs.master", "160.2.3", "tools", "Microsoft.SqlServer.Dacpacs.Master.dacpac"), dacpacPath); } [Fact] diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs index 638c60a7..4e38a4b3 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs @@ -4,11 +4,11 @@ namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests; internal class TestPackage : IPackageMetadata { - public static readonly string PackageBasePath = Path.Combine(Environment.GetEnvironmentVariable("HOME") ?? "", ".nuget", "packages", "microsoft.sqlserver.dacpacs.master", "160.2.3"); + public static readonly string NuGetPackageCache = Path.Combine(Environment.GetEnvironmentVariable("HOME") ?? Environment.GetEnvironmentVariable("USERPROFILE") ?? string.Empty, ".nuget", "packages"); public string PackageId { get; } = "Microsoft.SqlServer.Dacpacs.Master"; public Version PackageVersion { get; } = new Version(160, 2, 3); - public string PackagePath { get; } = PackageBasePath; + public string PackagePath { get; } = Path.Combine(NuGetPackageCache, "microsoft.sqlserver.dacpacs.master", "160.2.3"); } \ No newline at end of file From ef51baa53c37374034847d1667e626a31ec4373a Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 17 Dec 2024 15:59:14 +0100 Subject: [PATCH 11/13] Replace MS package with a more acurate sample package Add integration test Signed-off-by: Jonathan Mezach --- Directory.Packages.props | 2 +- ...Hosting.SqlDatabaseProjects.AppHost.csproj | 2 +- .../Program.cs | 3 +-- ...Aspire.Hosting.SqlDatabaseProjects.targets | 2 +- .../AddSqlPackageTests.cs | 13 +++++----- .../AppHostTests.cs | 25 ++++++++++++++++++- .../TestPackage.cs | 6 ++--- 7 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6dd27f64..d4f3842b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -53,7 +53,7 @@ - + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj index abc9119f..9c25b95b 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost.csproj @@ -12,7 +12,7 @@ - + diff --git a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs index f8437fb1..27b67221 100644 --- a/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs +++ b/examples/sql-database-projects/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.AppHost/Program.cs @@ -6,8 +6,7 @@ builder.AddSqlProject("sdk-project") .WithReference(server); -builder.AddSqlPackage("dacpac-project") - .WithDacpac("tools/master.dacpac") +builder.AddSqlPackage("chinook") .WithReference(server); builder.Build().Run(); diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets index 81793f2b..4e6dca35 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/build/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.targets @@ -13,7 +13,7 @@ DependsOnTargets="_CreateAspireProjectResources"> - $([System.Text.RegularExpressions.Regex]::Replace($([System.IO.Path]::GetFileNameWithoutExtension(%(_AspirePackageResource.Identity))), $(_GeneratedClassNameFixupRegex), '_')) + $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.Identity), $(_GeneratedClassNameFixupRegex), '_')) $([System.Text.RegularExpressions.Regex]::Replace(%(_AspirePackageResource.AspirePackageMetadataTypeName), $(_GeneratedClassNameFixupRegex), '_')) @(_AspirePackageResource->'%(Identity)'->Replace('.', '_')) $([System.String]::new('$(NuGetPackageRoot)%(_AspirePackageResource.Identity)/%(_AspirePackageResource.Version)').ToLower()) diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs index b4d0530c..22426b16 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs @@ -9,7 +9,7 @@ public void AddSqlPackage_WithPackageMetadata() { // Arrange var appBuilder = DistributedApplication.CreateBuilder(); - appBuilder.AddSqlPackage("master"); + appBuilder.AddSqlPackage("chinook"); // Act using var app = appBuilder.Build(); @@ -17,11 +17,12 @@ public void AddSqlPackage_WithPackageMetadata() // Assert var sqlProjectResource = Assert.Single(appModel.Resources.OfType()); - Assert.Equal("master", sqlProjectResource.Name); + Assert.Equal("chinook", sqlProjectResource.Name); var dacpacPath = sqlProjectResource.GetDacpacPath(); Assert.NotNull(dacpacPath); - Assert.Equal(Path.Combine(TestPackage.NuGetPackageCache, "microsoft.sqlserver.dacpacs.master", "160.2.3", "tools", "Microsoft.SqlServer.Dacpacs.Master.dacpac"), dacpacPath); + Assert.Equal(Path.Combine(TestPackage.NuGetPackageCache, "erikej.dacpac.chinook", "1.0.0", "tools", "ErikEJ.Dacpac.Chinook.dacpac"), dacpacPath); + Assert.True(File.Exists(dacpacPath)); } [Fact] @@ -29,7 +30,7 @@ public void AddSqlPackage_WithExplicitRelativePath() { // Arrange var appBuilder = DistributedApplication.CreateBuilder(); - appBuilder.AddSqlPackage("master").WithDacpac("tools/master.dacpac"); + appBuilder.AddSqlPackage("chinook").WithDacpac("tools/ErikEJ.Dacpac.Chinook2.dacpac"); // Act using var app = appBuilder.Build(); @@ -37,10 +38,10 @@ public void AddSqlPackage_WithExplicitRelativePath() // Assert var sqlProjectResource = Assert.Single(appModel.Resources.OfType()); - Assert.Equal("master", sqlProjectResource.Name); + Assert.Equal("chinook", sqlProjectResource.Name); var dacpacPath = sqlProjectResource.GetDacpacPath(); Assert.NotNull(dacpacPath); - Assert.True(File.Exists(dacpacPath)); + Assert.Equal(Path.Combine(TestPackage.NuGetPackageCache, "erikej.dacpac.chinook", "1.0.0", "tools", "ErikEJ.Dacpac.Chinook2.dacpac"), dacpacPath); } } \ No newline at end of file diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs index f5a88138..297e67cd 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AppHostTests.cs @@ -8,7 +8,7 @@ namespace CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests; public class AppHostTests(AspireIntegrationTestFixture fixture) : IClassFixture> { [Fact] - public async Task ResourceStartsAndRespondsOk() + public async Task ProjectBasedResourceStartsAndRespondsOk() { string resourceName = "sdk-project"; await fixture.ResourceNotificationService.WaitForResourceAsync(resourceName, KnownResourceStates.Finished).WaitAsync(TimeSpan.FromMinutes(5)); @@ -29,4 +29,27 @@ public async Task ResourceStartsAndRespondsOk() var result = await command.ExecuteScalarAsync(); Assert.Equal(1, result); } + + [Fact] + public async Task PackageBasedResourceStartsAndRespondsOk() + { + string resourceName = "chinook"; + await fixture.ResourceNotificationService.WaitForResourceAsync(resourceName, KnownResourceStates.Finished).WaitAsync(TimeSpan.FromMinutes(5)); + + string? connectionString = await fixture.GetConnectionString("TargetDatabase"); + Assert.NotNull(connectionString); + + using var connection = new SqlConnection(connectionString); + await connection.OpenAsync(); + + using var command = connection.CreateCommand(); + command.CommandText = + "SELECT COUNT(1) " + + "FROM INFORMATION_SCHEMA.TABLES " + + "WHERE TABLE_SCHEMA = 'dbo' " + + "AND TABLE_NAME = 'InvoiceLine'"; + + var result = await command.ExecuteScalarAsync(); + Assert.Equal(1, result); + } } \ No newline at end of file diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs index 4e38a4b3..ce74b78c 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/TestPackage.cs @@ -6,9 +6,9 @@ internal class TestPackage : IPackageMetadata { public static readonly string NuGetPackageCache = Path.Combine(Environment.GetEnvironmentVariable("HOME") ?? Environment.GetEnvironmentVariable("USERPROFILE") ?? string.Empty, ".nuget", "packages"); - public string PackageId { get; } = "Microsoft.SqlServer.Dacpacs.Master"; + public string PackageId { get; } = "ErikEJ.Dacpac.Chinook"; - public Version PackageVersion { get; } = new Version(160, 2, 3); + public Version PackageVersion { get; } = new Version(1, 0, 0); - public string PackagePath { get; } = Path.Combine(NuGetPackageCache, "microsoft.sqlserver.dacpacs.master", "160.2.3"); + public string PackagePath { get; } = Path.Combine(NuGetPackageCache, "erikej.dacpac.chinook", "1.0.0"); } \ No newline at end of file From 7f72f70f9a102dcab94bdd66075ee7aa2cd23641 Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Tue, 17 Dec 2024 16:16:06 +0100 Subject: [PATCH 12/13] Make tests more robust cross-platform Signed-off-by: Jonathan Mezach --- .../AddSqlPackageTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs index 22426b16..3b7b48dd 100644 --- a/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs +++ b/tests/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects.Tests/AddSqlPackageTests.cs @@ -30,7 +30,7 @@ public void AddSqlPackage_WithExplicitRelativePath() { // Arrange var appBuilder = DistributedApplication.CreateBuilder(); - appBuilder.AddSqlPackage("chinook").WithDacpac("tools/ErikEJ.Dacpac.Chinook2.dacpac"); + appBuilder.AddSqlPackage("chinook").WithDacpac(Path.Combine("tools", "ErikEJ.Dacpac.Chinook2.dacpac")); // Act using var app = appBuilder.Build(); From 4610d83d7d91cc491c6e82437080bebf5977f5da Mon Sep 17 00:00:00 2001 From: Jonathan Mezach Date: Wed, 18 Dec 2024 08:59:09 +0100 Subject: [PATCH 13/13] Resolve PR comments Signed-off-by: Jonathan Mezach --- .../SqlProjectBuilderExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs index 89828749..ced1c66a 100644 --- a/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs +++ b/src/CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects/SqlProjectBuilderExtensions.cs @@ -30,7 +30,7 @@ static SqlProjectBuilderExtensions() /// An instance to add the SQL Server Database project to. /// Name of the resource. /// An that can be used to further customize the resource. - public static IResourceBuilder AddSqlProject(this IDistributedApplicationBuilder builder, [ResourceName]string name) + public static IResourceBuilder AddSqlProject(this IDistributedApplicationBuilder builder, [ResourceName] string name) where TProject : IProjectMetadata, new() { ArgumentNullException.ThrowIfNull(builder, nameof(builder)); @@ -46,7 +46,7 @@ public static IResourceBuilder AddSqlProject(this /// An instance to add the SQL Server Database project to. /// Name of the resource. /// An that can be used to further customize the resource. - public static IResourceBuilder AddSqlProject(this IDistributedApplicationBuilder builder, [ResourceName]string name) + public static IResourceBuilder AddSqlProject(this IDistributedApplicationBuilder builder, [ResourceName] string name) { ArgumentNullException.ThrowIfNull(builder, nameof(builder)); ArgumentNullException.ThrowIfNull(name, nameof(name)); @@ -64,7 +64,7 @@ public static IResourceBuilder AddSqlProject(this IDistribut /// An instance to add the SQL Server Database project to. /// Name of the resource. /// Am that can be used to further customize the resource. - public static IResourceBuilder AddSqlPackage(this IDistributedApplicationBuilder builder, [ResourceName]string name) + public static IResourceBuilder AddSqlPackage(this IDistributedApplicationBuilder builder, [ResourceName] string name) where TPackage : IPackageMetadata, new() { ArgumentNullException.ThrowIfNull(builder, nameof(builder));