我正在使用 sqlpackage.exe 部署 dacpac,并且需要为 dacpac 中的部署后脚本传递 SqlCMD 变量。我在这里和这里找到了一个相关的问题。
但我收到以下错误: 缺少以下 SqlCmd 变量的值:BuildVersion 描述。Description=$Description :术语“Description=$Description”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
请帮我。
将 SQLCMD 变量传递给 SQLPackage 的正确开关是这样的 /v:Description=$Description
Powershell 引用有点棘手。这是给你的一个例子:
https://gist.github.com/davoscollective/adf9b890984e51d8dee2
& "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe" ` #Note this is SQL Server 2012 specific directory, alter as needed
/Action:Publish `
/SourceFile:$sourceFile `
/TargetServerName:$targetServerName `
/TargetDatabaseName:$targetDBname `
/V:SQLCMDVariable1=$SQLCMDVariable1 ` #If your project includes other database references, or pre/post deployment scripts uses SQLCMD variables
/v:SQLCMDVariable2=$SQLCMDVariable2 `
It seems like you are using Powershell to call SqlPackage based on the cmdlet error. If this is the case ensure the Dollar symbols are escaped with a inverted apostrophe i.e.
ie Description=`$Description
Could you post the full command you are passing?