伙计,
我们正在内部使用TFS 2017,并正在努力调配/部署到Azure网站和数据库。我们的Azure数据库设置/更新任务运行良好,但是在实现网站部分自动化之前,我们需要执行一个临时步骤,将Web程序包从内部版本复制到暂存共享中。
此步骤在TFS vstsagent下的部署组上运行,如下所示:
步骤5)使用Newtonsoft.Json的合并功能执行。
# Load the Newtonsoft.Json dll
$asmNewtonsoftJson = [Reflection.Assembly]::LoadFile([io.path]::combine($FolderToZip, "Newtonsoft.Json.dll"))
# Read the appsettings.json file and store as a JObject
$appSettingsPath = [io.path]::combine($folderToZip, "appsettings.json")
$appSettingsJson = (Get-Content $appSettingsPath | Out-String)
$appSettings = [Newtonsoft.Json.Linq.JObject]::Parse($appSettingsJson)
# Read the master appsettings.json file from the env and store as a JObject
$appSettingsMasterPath = [io.path]::combine($AppSettingsMasterFolderPath, $Environment + ".appsettings.json")
$appSettingsMasterJson = (Get-Content $appSettingsMasterPath | Out-String)
$appSettingsMaster = [Newtonsoft.Json.Linq.JObject]::Parse($appSettingsMasterJson)
# Merge the master appsettings.json file into the appsettings.json file
$jms = New-Object Newtonsoft.Json.Linq.JsonMergeSettings
$jms.MergeArrayHandling = [Newtonsoft.Json.Linq.MergeArrayHandling]::Merge
$appSettings.Merge($appSettingsMaster, $jms)
# Write out the updated appsettings.json file
[io.File]::WriteAllText($appSettingsPath, $appSettings.ToString())
注意:$ folderToZip包含Web软件包的扩展内容。该文件还包含Newtonsoft.Json dll(可能还有其依赖项)。
上面的代码在Windows Powershell ISE应用程序中工作正常,但是在TFS版本定义任务中运行时失败。
它在步骤5)失败,并显示以下错误:
2018-10-11T19:29:39.1790546Z ##[error]Unable to find type [Newtonsoft.Json.Linq.JObject].
At C:\vstsagent\A1\_work\r7\a\<path>\drop\Build\mymergescript.ps1:84 char:20
$appSettings = [Newtonsoft.Json.Linq.JObject]::Parse($appSettings)
CategoryInfo : InvalidOperation: (Newtonsoft.Json.Linq.JObject:TypeName) [], RuntimeException
FullyQualifiedErrorId : TypeNotFound
当由TFS vstsagent部署时,似乎Newtonsoft.Json.dll没有正确加载。
感谢您的帮助。