I'm parsing a csproj file for a nuget install and I've got a node that needs to be altered. The node in question is the node named "Generator" where it's value equals "TextTemplatingFileGenerator" and it's parent node has an attribute of "WebConfigSettingsGeneratorScript.tt" (the second part isn't in here yet).
Here's the script that I've got, but it's not quite done. It's working, but it saves an empty file. Also, it doesn't have the 2nd part of my where clause, which is
$path = 'C:\Projects\Intouch\NuGetTestPackage\NuGetTestPackage'
cd $path
$files = get-childitem -recurse -filter *.csproj
foreach ($file in $files){
""
"Filename: {0}" -f $($file.Name)
"=" * ($($file.FullName.Length) + 10)
if($file.Name -eq 'NuGetTestPackage1.csproj'){
$xml = gc $file.FullName |
Where-Object { $_.Project.ItemGroup.None.Generator -eq 'TextTemplatingFileGenerator' } |
ForEach-Object { $_.Project.ItemGroup.None.Generator = '' }
Set-Content $file.FullName $xml
}
}
Here's a basic version of the XML:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="T4\WebConfigSettingGeneratorScript.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>WebConfigSettingGeneratorScript.txt</LastGenOutput>
</None>
Thanks a lot. I'm a total PowerShell n00b!