-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jonathan Mezach <[email protected]>
- Loading branch information
Showing
6 changed files
with
94 additions
and
84 deletions.
There are no files selected for viewing
64 changes: 0 additions & 64 deletions
64
src/MSBuild.Sdk.SqlProj.Aspire/DataTierApplicationBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Aspire.Hosting.ApplicationModel; | ||
using Aspire.Hosting.Lifecycle; | ||
using Microsoft.Build.Locator; | ||
using MSBuild.Sdk.SqlProj.Aspire; | ||
|
||
namespace Aspire.Hosting; | ||
|
||
public static class SqlProjectBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a SQL Server Database Project resource to the application based on a referenced MSBuild.Sdk.SqlProj project. | ||
/// </summary> | ||
/// <typeparam name="TProject">Type that represents the project that produces the .dacpac file.</typeparam> | ||
/// <param name="builder">An <see cref="IDistributedApplicationBuilder"/> instance to add the SQL Server Database project to.</param> | ||
/// <param name="name">Name of the resource.</param> | ||
/// <returns>An <see cref="IResourceBuilder{T}"/> that can be used to further customize the resource.</returns> | ||
public static IResourceBuilder<SqlProjectResource> AddSqlProject<TProject>(this IDistributedApplicationBuilder builder, string name) | ||
where TProject : IProjectMetadata, new() | ||
{ | ||
if (!MSBuildLocator.IsRegistered) | ||
{ | ||
MSBuildLocator.RegisterDefaults(); | ||
} | ||
|
||
var resource = new SqlProjectResource(name); | ||
|
||
return builder.AddResource(resource) | ||
.WithAnnotation(new TProject()); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a SQL Server Database Project resource to the application. | ||
/// </summary> | ||
/// <param name="builder">An <see cref="IDistributedApplicationBuilder"/> instance to add the SQL Server Database project to.</param> | ||
/// <param name="name">Name of the resource.</param> | ||
/// <returns>An <see cref="IResourceBuilder{T}"/> that can be used to further customize the resource.</returns> | ||
public static IResourceBuilder<SqlProjectResource> AddSqlProject(this IDistributedApplicationBuilder builder, string name) | ||
{ | ||
var resource = new SqlProjectResource(name); | ||
|
||
return builder.AddResource(resource); | ||
} | ||
|
||
/// <summary> | ||
/// Specifies the path to the .dacpac file. | ||
/// </summary> | ||
/// <param name="builder">An <see cref="IResourceBuilder{T}"/> representing the SQL Server Database project.</param> | ||
/// <param name="dacpacPath">Path to the .dacpac file.</param> | ||
/// <returns>An <see cref="IResourceBuilder{T}"/> that can be used to further customize the resource.</returns> | ||
public static IResourceBuilder<SqlProjectResource> FromDacpac(this IResourceBuilder<SqlProjectResource> builder, string dacpacPath) | ||
{ | ||
if (!Path.IsPathRooted(dacpacPath)) | ||
{ | ||
dacpacPath = Path.Combine(builder.ApplicationBuilder.AppHostDirectory, dacpacPath); | ||
} | ||
|
||
return builder.WithAnnotation(new DacpacMetadataAnnotation(dacpacPath)); | ||
} | ||
|
||
/// <summary> | ||
/// Publishes the SQL Server Database project to the target <see cref="SqlServerDatabaseResource"/>. | ||
/// </summary> | ||
/// <param name="builder">An <see cref="IResourceBuilder{T}"/> representing the SQL Server Database project to publish.</param> | ||
/// <param name="target">An <see cref="IResourceBuilder{T}"/> representing the target <see cref="SqlServerDatabaseResource"/> to publish the SQL Server Database project to.</param> | ||
/// <returns>An <see cref="IResourceBuilder{T}"/> that can be used to further customize the resource.</returns> | ||
public static IResourceBuilder<SqlProjectResource> PublishTo( | ||
this IResourceBuilder<SqlProjectResource> builder, IResourceBuilder<SqlServerDatabaseResource> target) | ||
{ | ||
builder.ApplicationBuilder.Services.TryAddLifecycleHook<PublishSqlProjectLifecycleHook>(); | ||
builder.WithAnnotation(new TargetDatabaseResourceAnnotation(target.Resource.Name), ResourceAnnotationMutationBehavior.Replace); | ||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters