Est-il possible d'utiliser la transformation de document XML de Microsoft, pour préparer web.configs, en dehors de MSBuild ? J'aimerais utiliser PowerShell pour effectuer ces transformations sans avoir à l'exécuter via le moteur MSBuild. Si Microsoft avait utilisé le XSLT standard, cela aurait été facile à faire dans PowerShell. D'après ce que je peux dire, je dois utiliser leur C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll qui nécessite un moteur de génération. Merci
Réponse
Trop de publicités?
c_wiz_kid
Points
81
J'ai un peu mis à jour le script pour le faire fonctionner avec la dernière version de powershell et le rendre un peu plus facile.
function XmlDocTransform($xml, $xdt)
{
$scriptpath = $PSScriptRoot + "\"
$xmlpath = $scriptpath + $xml
$xdtpath = $scriptpath + $xdt
if (!($xmlpath) -or !(Test-Path -path ($xmlpath) -PathType Leaf)) {
throw "Base file not found. $xmlpath";
}
if (!($xdtpath) -or !(Test-Path -path ($xdtpath) -PathType Leaf)) {
throw "Transform file not found. $xdtpath";
}
Add-Type -LiteralPath "$PSScriptRoot\Microsoft.Web.XmlTransform.dll"
$xmldoc = New-Object Microsoft.Web.XmlTransform.XmlTransformableDocument;
$xmldoc.PreserveWhitespace = $true
$xmldoc.Load($xmlpath);
$transf = New-Object Microsoft.Web.XmlTransform.XmlTransformation($xdtpath);
if ($transf.Apply($xmldoc) -eq $false)
{
throw "Transformation failed."
}
$xmldoc.Save($xmlpath);
Write-Host "Transformation succeeded" -ForegroundColor Green
}
Et pour invoquer la fonction, utilisez
XmlDocTransform "App.config" "App.acc.config"