-
Notifications
You must be signed in to change notification settings - Fork 674
Open
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
I tried to use the following to run a sql script against the database
builder.AddExecutable("dbMigrator", "sqlcmd", packageDir)
.WithArgs(
"-S", $"127.0.0.1,{sql.Resource.PrimaryEndpoint.Property(EndpointProperty.Port)}",
"-U", "sa",
"-P", sql.Resource.PasswordParameter,
"-i", patchedUpgradeScriptPath
)
However because WithArgs()
takes an object array, the -S
argument was treated as a regular interpolated string and not a reference expression, with the final args ending up as:
[
"-S",
// Expected `Aspire.Hosting.ApplicationModel.EndpointReferenceExpression`
"127.0.0.1,Aspire.Hosting.ApplicationModel.EndpointReferenceExpression",
"-U",
"sa",
"-P",
"REDACTED",
"-i",
"REDACTED"
]
Describe the solution you'd like
I'd like to see some kind of early detection to help prevent such errors. Two ideas:
- Make
ToString()
on ReferenceExpressions throw / log an error, rather than ending up - An analyzer to detect when a Reference Expression is detected within a regular interpolated string.
Additional context
For anyone hitting the original issue, you can work around that by explicitly building a ReferenceExpression
, and then referencing that.
var migrations = builder.AddExecutable("dbMigrator", "sqlcmd", packageDir)
.WithArgs(
"-S", serverExpresison,
"-U", "sa",
"-P", sql.Resource.PasswordParameter,
"-i", patchedUpgradeScriptPath
)
Metadata
Metadata
Assignees
Labels
area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication