1

所以我试图在 tfs 构建后直接执行 ps 脚本。当脚本在构建后运行时,会出现一个错误,指出源文件必须具有有效的 .dacpac 扩展名。下面是代码

#Powershell script to capture the latest version of the dacpac generated for the source file
$srcdir= get-childitem '\\a\b\c\d\e\f' | Where {$_.LastWriteTime} | select -last 1
$srcpathitem= Join-Path \\a\b\c\d\e\f$srcdir
$filesource= get-childitem -path $srcpathitem -filter abc.dacpac
$finalsource= Join-Path $srcpathitem $filesource
#Latest version of the target file dacpac created
$tgtdir= get-childitem '\\1\2\3\4\5\6' | Where {$_.LastWriteTime} | select -last 1
$tgtpathitem= Join-Path \\1\2\3\4\5\6 $tgtdir
$filetarget= get-childitem -path $tgtpathitem -filter EFT.dacpac
$finaltarget= Join-Path $tgtpathitem $filesource
&"\\xyz\build\xyz\xyz\Scripts\DAC\bin\SqlPackage.exe" /a:Script `
/Sourcefile:$finalsource `
/TargetFile:$finaltarget `
/op:"\\xyz\build\xyz\xyz\Scripts\123-script.sql" `

抱歉,由于隐私问题,文件位置和文件夹名称已被赋予别名。

所以倒数第三个是 dacpac 出现错误的地方。所以请告诉如何传递文件路径,以免出现任何错误。并且仅供参考,路径不能被硬编码,因为文件夹在几个小时后自动创建了较新的版本。

4

2 回答 2

0

我假设您的以下代码可以成功获取文件:

$filesource= get-childitem -path $srcpathitem -filter abc.dacpac

然后如果你在powershell中写出“$filesource”,你会发现值只是“abc.dacpac”。所以你可以尝试将“ /Sourcefile:$finalsource ”更新为“ /Sourcefile:$finalsource.FullName ”将返回整个文件路径。

于 2016-02-26T10:03:57.123 回答
0

尝试使用

/Sourcefile:$(finalsource)`
/TargetFile:$(finaltarget)`

代替

/Sourcefile:$finalsource `
/TargetFile:$finaltarget `
于 2016-02-26T09:32:47.077 回答