.targetsファイル(XML)の1つの値を変更して文書を保存するNuGetパッケージのinit.ps1スクリプトを作成しようとしています。スクリプトはすべて正常にエラーなく実行しますが、ドキュメントをチェックすると変更されません。ここでNuGet初期化スクリプト中にXML文書を保存できない
はスクリプトです:
Param($installPath, $toolsPath, $package)
$proj = Get-Project
$pack = $package
# Detect if the project installing the NuGet package is a web application and
# alters an xml element value in the .targets value to prevent duplication
# of application resources when published.
if ($proj.ExtenderNames -contains "WebApplication") {
# Begin to build neccessary path strings to find the .targets file.
# The targets file is currently located in
# \packages\packageName.packageVersion\build\packageName.targets.
$packageName = [string]$pack.Id
$packageRootDir = $installPath
# packageName.Version\build
$packageBuildFolderPath = Join-Path $packageRootDir "build"
# packageName.Version\build\packageName
$targetsFilePath = Join-Path $packageBuildFolderPath ($packageName + ".targets")
"$targetsFilePath"
if (Test-Path $targetsFilePath) {
# If the targets file path has correctly located the file then
# we edit the targets file to alter the CopyToOutputDirectory element.
# Load the targets file as an xml object
$xml = New-Object System.Xml.XmlDocument
$xml.Load($targetsFilePath)
"xml loaded"
# Search each ItemGroup element for the one containing a Content element.
foreach ($group in $xml.Project.ItemGroup) {
$nodeExists = $group.Content.CopyToOutputDirectory
if ($nodeExists) {
"$nodeExists"
# Edits the value when we find the correct node
$nodeExists = "Never"
"$nodeExists"
}
}
"xml modified"
# Save the updated document to the correct place.
$savePath = [string]$targetsFilePath
"$savePath"
$xml.Save($savePath)
"xml Saved to $savePath"
}
}
そして、ここでは最初からパッケージマネージャの出力は、スクリプトブロックの末尾にある:
Executing script file 'path to tools/Init.ps1' 'correct path to package/build/package.targets' xml loaded Always Never xml modified 'correct path to package/build/package.targets' xml Saved to 'correct path to package/build/package.targets'
実際の質問とは別に、ファイルで何を修正しようとしていますか? /なぜそれが必要ですか? –